Skip to main content

Serials

Struct Serials 

Source
pub struct Serials { /* private fields */ }
Expand description

Serial number management interface.

Implementations§

Source§

impl Serials

Source

pub fn create(&self, input: CreateSerialNumber) -> Result<SerialNumber>

Create a serial number.

§Example
use stateset_embedded::{Commerce, CreateSerialNumber};
use chrono::Utc;

let commerce = Commerce::new(":memory:")?;

let serial = commerce.serials().create(CreateSerialNumber {
    serial: Some("SN-12345".into()),
    sku: "WIDGET-001".into(),
    lot_number: Some("LOT-2025-001".into()),
    manufactured_at: Some(Utc::now()),
    ..Default::default()
})?;
Source

pub fn create_bulk( &self, input: CreateSerialNumbersBulk, ) -> Result<Vec<SerialNumber>>

Create multiple serial numbers in bulk.

§Example
use stateset_embedded::{Commerce, CreateSerialNumbersBulk};

let commerce = Commerce::new(":memory:")?;

// Generate 100 serial numbers with prefix
let serials = commerce.serials().create_bulk(CreateSerialNumbersBulk {
    sku: "WIDGET-001".into(),
    quantity: 100,
    prefix: Some("WGT".into()),
    lot_number: Some("LOT-2025-001".into()),
    ..Default::default()
})?;

println!("Created {} serial numbers", serials.len());
Source

pub fn get(&self, id: Uuid) -> Result<Option<SerialNumber>>

Get a serial by ID.

Source

pub fn get_by_serial(&self, serial: &str) -> Result<Option<SerialNumber>>

Get a serial by its serial number string.

§Example
use stateset_embedded::Commerce;

let commerce = Commerce::new(":memory:")?;

if let Some(serial) = commerce.serials().get_by_serial("SN-12345")? {
    println!("Serial {} is currently {}", serial.serial, serial.status);
}
Source

pub fn list(&self, filter: SerialFilter) -> Result<Vec<SerialNumber>>

List serials with optional filtering.

Source

pub fn update( &self, id: Uuid, input: UpdateSerialNumber, ) -> Result<SerialNumber>

Update a serial number.

Source

pub fn delete(&self, id: Uuid) -> Result<()>

Delete a serial (only if never used).

Source

pub fn change_status(&self, input: ChangeSerialStatus) -> Result<SerialNumber>

Change serial status with full tracking.

§Example
use stateset_embedded::{Commerce, ChangeSerialStatus, SerialStatus};
use uuid::Uuid;

let commerce = Commerce::new(":memory:")?;

commerce.serials().change_status(ChangeSerialStatus {
    serial_id: Uuid::new_v4(),
    new_status: SerialStatus::InService,
    reference_type: Some("repair_order".into()),
    reference_id: Some(Uuid::new_v4()),
    notes: Some("Sent for repair".into()),
    ..Default::default()
})?;
Source

pub fn mark_sold( &self, id: Uuid, customer_id: Uuid, order_id: Option<Uuid>, ) -> Result<SerialNumber>

Mark a serial as sold.

Source

pub fn mark_shipped(&self, id: Uuid, shipment_id: Uuid) -> Result<SerialNumber>

Mark a serial as shipped.

Source

pub fn mark_returned(&self, id: Uuid, return_id: Uuid) -> Result<SerialNumber>

Mark a serial as returned.

Source

pub fn activate(&self, id: Uuid) -> Result<SerialNumber>

Activate a serial (e.g., for warranty start).

Source

pub fn quarantine(&self, id: Uuid, reason: &str) -> Result<SerialNumber>

Quarantine a serial.

Source

pub fn release_quarantine(&self, id: Uuid) -> Result<SerialNumber>

Release a serial from quarantine.

Source

pub fn scrap(&self, id: Uuid, reason: &str) -> Result<SerialNumber>

Scrap a serial.

Source

pub fn reserve(&self, input: ReserveSerialNumber) -> Result<SerialReservation>

Reserve a serial for an order or other purpose.

§Example
use stateset_embedded::{Commerce, ReserveSerialNumber};
use uuid::Uuid;

let commerce = Commerce::new(":memory:")?;

let reservation = commerce.serials().reserve(ReserveSerialNumber {
    serial_id: Uuid::new_v4(),
    reference_type: "order".into(),
    reference_id: Uuid::new_v4(),
    reserved_by: Some("sales_user".into()),
    expires_in_seconds: Some(3600), // 1 hour
    ..Default::default()
})?;

println!("Reservation created, expires at {:?}", reservation.expires_at);
Source

pub fn release_reservation(&self, reservation_id: Uuid) -> Result<()>

Release a reservation.

Source

pub fn confirm_reservation(&self, reservation_id: Uuid) -> Result<()>

Confirm a reservation (finalize the allocation).

Source

pub fn move_serial(&self, input: MoveSerial) -> Result<SerialNumber>

Move a serial to a new location.

Source

pub fn transfer_ownership( &self, input: TransferSerialOwnership, ) -> Result<SerialNumber>

Transfer ownership of a serial.

§Example
use stateset_embedded::{Commerce, TransferSerialOwnership};
use uuid::Uuid;

let commerce = Commerce::new(":memory:")?;

commerce.serials().transfer_ownership(TransferSerialOwnership {
    serial_id: Uuid::new_v4(),
    new_owner_id: Uuid::new_v4(),
    new_owner_type: "customer".into(),
    notes: Some("Warranty transfer requested".into()),
    ..Default::default()
})?;
Source

pub fn get_history( &self, serial_id: Uuid, filter: SerialHistoryFilter, ) -> Result<Vec<SerialHistory>>

Get serial history.

§Example
use stateset_embedded::{Commerce, SerialHistoryFilter};
use uuid::Uuid;

let commerce = Commerce::new(":memory:")?;

let history = commerce.serials().get_history(
    Uuid::new_v4(),
    SerialHistoryFilter {
        limit: Some(50),
        ..Default::default()
    },
)?;

for event in history {
    println!("{}: {} -> {}", event.event_type, event.from_status, event.to_status);
}
Source

pub fn lookup(&self, serial: &str) -> Result<Option<SerialLookupResult>>

Full serial lookup with related data.

Returns the serial along with lot info, warranty status, and recent history.

§Example
use stateset_embedded::Commerce;

let commerce = Commerce::new(":memory:")?;

if let Some(result) = commerce.serials().lookup("SN-12345")? {
    println!("Serial: {}", result.serial.serial);
    println!("SKU: {}", result.serial.sku);
    println!("Status: {}", result.serial.status);
    if let Some(warranty) = result.warranty_status {
        println!("Warranty active: {}", warranty.is_active);
    }
}
Source

pub fn validate(&self, serial: &str) -> Result<SerialValidation>

Validate a serial number.

Returns validation info without the full serial data.

Source

pub fn get_available(&self, sku: &str, limit: u32) -> Result<Vec<SerialNumber>>

Get available serials for a SKU.

Source

pub fn get_for_lot(&self, lot_id: Uuid) -> Result<Vec<SerialNumber>>

Get serials for a lot.

Source

pub fn get_for_customer(&self, customer_id: Uuid) -> Result<Vec<SerialNumber>>

Get serials owned by a customer.

Source

pub fn count(&self, filter: SerialFilter) -> Result<u64>

Count serials matching filter.

Source

pub fn create_batch( &self, inputs: Vec<CreateSerialNumber>, ) -> Result<BatchResult<SerialNumber>>

Create multiple serials with partial success handling.

Source

pub fn get_batch(&self, ids: Vec<Uuid>) -> Result<Vec<SerialNumber>>

Get multiple serials by ID.

Source

pub fn get_batch_by_serial( &self, serials: Vec<String>, ) -> Result<Vec<SerialNumber>>

Get multiple serials by serial string.

Source

pub fn is_available(&self, serial: &str) -> Result<bool>

Check if a serial is available for sale.

Source

pub fn can_ship(&self, serial: &str) -> Result<bool>

Check if a serial can be shipped.

Trait Implementations§

Source§

impl Debug for Serials

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more