>>105707876>Would the first example, directly transferred to Rust by using references instead of pointers, even fly by the borrow checker?You just need to annotate adj with internal mutability.
>Aliasing?There is no aliasing here.
>I'd love to see the equivalent Rust code as you describe it.use std::collections::HashMap;
use std::cell::RefCell;
struct Vertex {
adj: RefCell<Vec<(f32, &'static Vertex)>>,
name: String,
}
impl Vertex {
fn new(name: String) -> Self {
Vertex {
adj: RefCell::new(vec![]),
name,
}
}
}
struct Graph {
work: HashMap<String, &'static Vertex>,
}
impl Graph {
fn add_vertex(&mut self, name: String) {
if self.work.get(&name).is_none() {
let v = Vertex::new(name.clone());
let v = Box::leak(Box::new(v));
self.work.insert(name, v);
}
print!("\nVertex already exists!"); // ???
}
fn add_edge(&mut self, from: &str, to: &str, cost: f32) {
let f = self.work.get(from).unwrap();
let t = self.work.get(to).unwrap();
f.adj.borrow_mut().push((cost, t));
}
}
>Are the cycles in references really that easy in Rust without using unsafe and without using RC or ARC?Rc and Arc is RAII. This code doesn't free anything so you do not need RAII for anything.
>I see, you're just shitposting and not even reading the comments in that thread.If I was shitposting I would tell you to fuck off back to pleddit you retard. If you want to make an argument then state it yourself. If you rather spam reddit links hoping something sticks then get the fuck out of there.
>>105707882Not an argument.