From 29996fdfc61759b481b00187961571016295c7f9 Mon Sep 17 00:00:00 2001 From: Mohammed Ghannam Date: Fri, 1 Nov 2024 13:40:46 +0100 Subject: [PATCH 1/2] Move scip_ptr() method to trait --- src/model.rs | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/src/model.rs b/src/model.rs index 64a0b73..e1199ae 100644 --- a/src/model.rs +++ b/src/model.rs @@ -108,10 +108,6 @@ pub struct ModelSolving { } impl Model { - fn scip(&self) -> Rc { - self.scip.clone() - } - /// Sets the objective sense of the model to the given value and returns the same `Model` instance. /// /// # Arguments @@ -343,10 +339,6 @@ impl Model { } impl ModelSolving { - fn scip(&self) -> Rc { - self.scip.upgrade().expect("SCIP instance was dropped") - } - /// Adds a new variable to the model with the given lower bound, upper bound, objective coefficient, name, and type. /// /// # Arguments @@ -457,10 +449,6 @@ impl ModelSolving { } impl Model { - fn scip(&self) -> Rc { - self.scip.clone() - } - /// Returns the objective value of the best solution found by the optimization model. pub fn obj_val(&self) -> f64 { self.scip.obj_val() @@ -1167,18 +1155,41 @@ macro_rules! impl_WithSolvingStats { impl_WithSolvingStats!(for Model, ModelSolving, Model); -impl Model { - /// Returns a pointer to the underlying SCIP instance. +pub(crate) trait HasScipPtr { + fn scip(&self) -> Rc;// Returns a pointer to the underlying SCIP instance. + + // Returns a pointer to the underlying SCIP instance. /// /// # Safety /// /// This method is unsafe because it returns a raw pointer to the underlying SCIP instance. /// The caller must ensure that the pointer is used safely and correctly. #[cfg(feature = "raw")] - pub unsafe fn scip_ptr(&self) -> *mut ffi::SCIP { - self.scip.raw + unsafe fn scip_ptr(&self) -> *mut ffi::SCIP { + self.scip().raw + } +} + +impl HasScipPtr for Model { + fn scip(&self) -> Rc { + self.scip.clone() + } +} + +impl HasScipPtr for Model { + fn scip(&self) -> Rc { + self.scip.clone() } +} + +impl HasScipPtr for ModelSolving { + fn scip(&self) -> Rc { + self.scip.upgrade().expect("SCIP instance was dropped") + } +} + +impl Model { /// Returns the status of the optimization model. pub fn status(&self) -> Status { self.scip.status() From 06d1a04754b3ef64cb3a260688b0b9cf465084e2 Mon Sep 17 00:00:00 2001 From: Mohammed Ghannam Date: Fri, 1 Nov 2024 13:41:14 +0100 Subject: [PATCH 2/2] Cargo fmt --- src/model.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/model.rs b/src/model.rs index e1199ae..1136d9d 100644 --- a/src/model.rs +++ b/src/model.rs @@ -1156,7 +1156,7 @@ macro_rules! impl_WithSolvingStats { impl_WithSolvingStats!(for Model, ModelSolving, Model); pub(crate) trait HasScipPtr { - fn scip(&self) -> Rc;// Returns a pointer to the underlying SCIP instance. + fn scip(&self) -> Rc; // Returns a pointer to the underlying SCIP instance. // Returns a pointer to the underlying SCIP instance. /// @@ -1188,7 +1188,6 @@ impl HasScipPtr for ModelSolving { } } - impl Model { /// Returns the status of the optimization model. pub fn status(&self) -> Status {