pub struct Factory<T: Aictable> { /* private fields */ }Expand description
A factory for generating unique IDs of a specific type.
Implementations§
Source§impl<T: Aictable> Factory<T>
impl<T: Aictable> Factory<T>
Sourcepub fn new(initial_value: T, looping: bool, rewind: bool) -> Self
pub fn new(initial_value: T, looping: bool, rewind: bool) -> Self
Creates a new Factory with the specified initial value, looping behavior, and rewind behavior.
It’s recommended to use a FactoryBuilder to build a Factory.
See the document of FactoryBuilder for details.
Sourcepub fn builder() -> FactoryBuilder<T>
pub fn builder() -> FactoryBuilder<T>
Returns a new FactoryBuilder.
Sourcepub fn consume<I>(&mut self, ids: I) -> Result<(), Error<T>>where
I: IntoIterator<Item = T>,
pub fn consume<I>(&mut self, ids: I) -> Result<(), Error<T>>where
I: IntoIterator<Item = T>,
Manually marks a list of IDs as used.
§Errors
- If any ID is already taken, it returns an
Error::AlreadyExist<T>.
Sourcepub fn next(&mut self) -> Result<T, Error<T>>
pub fn next(&mut self) -> Result<T, Error<T>>
Generates and returns the next unique ID.
§Errors
- If no more IDs can be generated, it returns an
Error::OutOfSpace. - If
Factory::loopingis false and the current ID is already the maximum value of the type, it returns anError::MaxReached.
Auto Trait Implementations§
impl<T> Freeze for Factory<T>where
T: Freeze,
impl<T> RefUnwindSafe for Factory<T>where
T: RefUnwindSafe,
impl<T> Send for Factory<T>where
T: Send,
impl<T> Sync for Factory<T>where
T: Sync,
impl<T> Unpin for Factory<T>where
T: Unpin,
impl<T> UnsafeUnpin for Factory<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Factory<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more