Skip to main content

Transaction

Struct Transaction 

Source
pub struct Transaction<'m> { /* private fields */ }
Expand description

An open edit on a Mesh. All writes go through it.

Every method validates its whole input before writing, so a returned validation error leaves the transaction unchanged and usable. If a write itself fails (out of memory), the transaction is poisoned and commit rolls it back.

Dropping a transaction without committing rolls it back.

Implementations§

Source§

impl Transaction<'_>

Source

pub fn mesh(&self) -> &Mesh

Read access to the mesh as edited so far.

Source

pub fn keeping_bound_channels<R>(&mut self, f: impl FnOnce(&mut Self) -> R) -> R

Runs f, whose topology writes do not outdate topology_bound channels: for an operation that keeps those channels true itself. Writes outside it, in the same transaction, still do.

Source

pub fn add_vertices(&mut self, positions: &[[f32; 3]]) -> Result<Vec<VertexId>>

Adds vertices without creation parents; source channels get their default value.

Source

pub fn add_vertex_with_parents( &mut self, position: [f32; 3], parents: &[(VertexId, f32)], ) -> Result<VertexId>

Adds a vertex created from existing vertices, e.g. an edge split creates a vertex with parents [(a, 0.5), (b, 0.5)]. Source channels derive its values from the parents according to their crate::TopologyPolicy.

Source

pub fn set_positions( &mut self, ids: &[VertexId], positions: &[[f32; 3]], ) -> Result<()>

Sets positions of existing vertices.

Source

pub fn remove_vertices(&mut self, ids: &[VertexId]) -> Result<()>

Removes vertices that no triangle uses.

Source

pub fn add_triangles( &mut self, triangles: &[[VertexId; 3]], ) -> Result<Vec<TriangleId>>

Adds triangles between existing vertices.

Source

pub fn remove_triangles(&mut self, ids: &[TriangleId]) -> Result<()>

Removes triangles. Their vertices stay; remove them separately if unused.

Source

pub fn set_triangles( &mut self, ids: &[TriangleId], triangles: &[[VertexId; 3]], ) -> Result<()>

Replaces the vertex ids of existing triangles (e.g. an edge flip).

Source

pub fn write_channel( &mut self, name: &str, ids: &[VertexId], values: &[f32], ) -> Result<()>

Writes source channel values: values holds width values per vertex in ids.

Source

pub fn drop_channel(&mut self, name: &str) -> Result<()>

Drops a source channel as part of this edit: it reads as absent from now on, undoing the edit restores it with its values, and redoing drops it again. For an operation whose new values for the channel are not well defined, where leaving it would mean stale values. The values stay in memory, counted in Patch::byte_size, until the patch is released from its history or the mesh is compacted. A channel added later under the same name is replaced when the edit is undone.

§Errors

StoreError::UnknownChannel, or StoreError::NotSourceChannel for a derived channel; the transaction stays usable.

Source

pub fn commit(self) -> Result<Patch>

Ends the transaction and returns its patch. An empty transaction returns an empty patch and leaves the revision unchanged. If memory for the patch runs out, the transaction is rolled back and OutOfMemory is returned.

Source

pub fn rollback(self)

Discards every change made in this transaction.

Trait Implementations§

Source§

impl Drop for Transaction<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<'m> !UnwindSafe for Transaction<'m>

§

impl<'m> Freeze for Transaction<'m>

§

impl<'m> RefUnwindSafe for Transaction<'m>

§

impl<'m> Send for Transaction<'m>

§

impl<'m> Sync for Transaction<'m>

§

impl<'m> Unpin for Transaction<'m>

§

impl<'m> UnsafeUnpin for Transaction<'m>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.