Make Vertex immutable

To match the C++ implementation. I meant to do this at the same time as the other metadata structs but missed it.
This commit is contained in:
Oliver Hamlet
2025-05-14 18:24:54 +01:00
parent beab02c3fe
commit 517dc6b43c
6 changed files with 60 additions and 78 deletions
+11 -10
View File
@@ -220,24 +220,25 @@ impl Database {
#[repr(transparent)]
pub struct Vertex(libloot::Vertex);
pub fn new_vertex(name: String) -> Box<Vertex> {
Box::new(Vertex(libloot::Vertex::new(name)))
pub fn new_vertex(name: String, out_edge_type: EdgeType) -> Result<Box<Vertex>, VerboseError> {
let mut vertex = libloot::Vertex::new(name);
if out_edge_type != EdgeType::None {
vertex = vertex.with_out_edge_type(out_edge_type.try_into()?);
}
Ok(Box::new(Vertex(vertex)))
}
impl Vertex {
// A value of 255 is used to indicate that there is no out edge.
pub fn out_edge_type(&self) -> Result<u8, VerboseError> {
pub fn out_edge_type(&self) -> Result<EdgeType, VerboseError> {
match self.0.out_edge_type() {
Some(e) => Ok(EdgeType::try_from(e)?.repr),
None => Ok(u8::MAX),
Some(e) => EdgeType::try_from(e).map_err(Into::into),
None => Ok(EdgeType::None),
}
}
pub fn set_out_edge_type(&mut self, out_edge_type: EdgeType) -> Result<(), VerboseError> {
self.0.set_out_edge_type(out_edge_type.try_into()?);
Ok(())
}
pub fn boxed_clone(&self) -> Box<Self> {
Box::new(Self(self.0.clone()))
}