Skip to content

Commit

Permalink
update public api
Browse files Browse the repository at this point in the history
  • Loading branch information
imrn99 committed Jan 2, 2025
1 parent 46a73b6 commit 2602627
Showing 1 changed file with 19 additions and 98 deletions.
117 changes: 19 additions & 98 deletions honeycomb-core/src/cmap/dim2/sews/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod one;
mod two;

use stm::{StmResult, Transaction};
use stm::Transaction;

use crate::{
cmap::{CMap2, CMapResult, DartIdType},
Expand Down Expand Up @@ -30,22 +30,26 @@ impl<T: CoordsFloat> CMap2<T> {
///
/// # Errors
///
/// This method should be called in a transactional context. The `Result` is then used to
/// validate the transaction; It should not be processed manually. The policy in case of
/// failure can be defined when creating the transaction, using `Transaction::with_control`.
/// This variant will abort the sew operation and raise an error if:
/// - the transaction cannot be completed,
/// - one (or more) attribute merge fails,
/// - for `I == 2`: orientation is inconsistent.
///
/// The returned error can be used in conjunction with transaction control to avoid any
/// modifications in case of failure at attribute level. The user can then choose, through its
/// transaction control policy, to retry or abort as he wishes (see `Transaction::with_control`).
///
/// # Panics
///
/// The method may panic if:
/// - `I >= 3` or `I == 0`
/// - the two darts are not I-sewable,
/// - for `I == 2`: orientation is inconsistent.
/// - the two darts are not I-sewable,
pub fn sew<const I: u8>(
&self,
trans: &mut Transaction,
ld: DartIdType,
rd: DartIdType,
) -> StmResult<()> {
) -> CMapResult<()> {
// these assertions + match on a const are optimized away
assert!(I < 3);
assert_ne!(I, 0);
Expand Down Expand Up @@ -77,16 +81,20 @@ impl<T: CoordsFloat> CMap2<T> {
///
/// # Errors
///
/// This method should be called in a transactional context. The `Result` is then used to
/// validate the transaction; It should not be processed manually. The policy in case of
/// failure can be defined when creating the transaction, using `Transaction::with_control`.
/// This variant will abort the unsew operation and raise an error if:
/// - the transaction cannot be completed,
/// - one (or more) attribute split fails,
///
/// The returned error can be used in conjunction with transaction control to avoid any
/// modifications in case of failure at attribute level. The user can then choose, through its
/// transaction control policy, to retry or abort as he wishes (see `Transaction::with_control`).
///
/// # Panics
///
/// The method may panic if:
/// - `I >= 3` or `I == 0`
/// - `ld` is already `I`-free,
pub fn unsew<const I: u8>(&self, trans: &mut Transaction, ld: DartIdType) -> StmResult<()> {
pub fn unsew<const I: u8>(&self, trans: &mut Transaction, ld: DartIdType) -> CMapResult<()> {
// these assertions + match on a const are optimized away
assert!(I < 3);
assert_ne!(I, 0);
Expand Down Expand Up @@ -152,91 +160,4 @@ impl<T: CoordsFloat> CMap2<T> {
_ => unreachable!(),
}
}

/// # `I`-sew operator.
///
/// This variant will abort the unsew operation and raise an error if attributes cannot be
/// merged correctly.
///
/// # Arguments
///
/// - `const I: u8` -- Sew dimension.
/// - `trans: &mut Transaction` -- Transaction associated to the operation.
/// - `ld: DartIdType` -- First dart ID.
/// - `rd: DartIdType` -- Second dart ID.
///
/// # Errors
///
/// This method will fail, returning an error, if:
/// - the transaction cannot be completed,
/// - one (or more) attribute merge fails,
/// - for `I == 2`: orientation is inconsistent.
///
/// The returned error can be used in conjunction with transaction control to avoid any
/// modifications in case of failure at attribute level. The user can then choose, through its
/// transaction control policy, to retry or abort as he wishes.
///
/// # Panics
///
/// The method may panic if:
/// - `I >= 3` or `I == 0`
/// - the two darts are not I-sewable,
pub fn try_sew<const I: u8>(
&self,
trans: &mut Transaction,
ld: DartIdType,
rd: DartIdType,
) -> CMapResult<()> {
// these assertions + match on a const are optimized away
assert!(I < 3);
assert_ne!(I, 0);
match I {
1 => self.try_one_sew(trans, ld, rd),
2 => self.try_two_sew(trans, ld, rd),
_ => unreachable!(),
}
}

/// # `I`-unsew operator.
///
/// This variant will abort the unsew operation and raise an error if attributes cannot be
/// split correctly.
///
/// # Arguments
///
/// - `const I: u8` -- Unsew dimension.
/// - `trans: &mut Transaction` -- Transaction associated to the operation.
/// - `ld: DartIdType` -- First dart ID.
///
/// The second dart ID is fetched using `I` and `ld`.
///
/// # Errors
///
/// This method will fail, returning an error, if:
/// - the transaction cannot be completed,
/// - one (or more) attribute split fails,
///
/// The returned error can be used in conjunction with transaction control to avoid any
/// modifications in case of failure at attribute level. The user can then choose, through its
/// transaction control policy, to retry or abort as he wishes.
///
/// # Panics
///
/// The method may panic if:
/// - `I >= 3` or `I == 0`
/// - `ld` is already `I`-free,
pub fn try_unsew<const I: u8>(
&self,
trans: &mut Transaction,
ld: DartIdType,
) -> CMapResult<()> {
// these assertions + match on a const are optimized away
assert!(I < 3);
assert_ne!(I, 0);
match I {
1 => self.try_one_unsew(trans, ld),
2 => self.try_two_unsew(trans, ld),
_ => unreachable!(),
}
}
}

0 comments on commit 2602627

Please sign in to comment.