pub struct Atom { /* private fields */ }Expand description
An immutable data container that represents a single version of content in the database.
Atoms are the fundamental building blocks of the database’s immutable data storage system. Each Atom contains:
- A unique identifier
- The source schema that defines its structure
- The public key of the creator
- Creation timestamp
- Optional reference to a previous version
- The actual content data
Atoms form a chain of versions through their prev_atom_uuid references, enabling
complete version history tracking. Once created, an Atom’s content cannot be modified,
ensuring data immutability.
Implementations§
Source§impl Atom
impl Atom
Sourcepub fn new(
source_schema_name: String,
source_pub_key: String,
content: Value,
) -> Self
pub fn new( source_schema_name: String, source_pub_key: String, content: Value, ) -> Self
Creates a new Atom with the given parameters.
§Arguments
source_schema_name- Name of the schema that defines this Atom’s structuresource_pub_key- Public key of the entity creating this Atomcontent- The actual data content stored in this Atom
§Returns
A new Atom instance with a content-based UUID and current timestamp
Sourcepub fn with_prev_version(self, prev_atom_uuid: String) -> Self
pub fn with_prev_version(self, prev_atom_uuid: String) -> Self
Creates a new Atom that references a previous version
Sourcepub fn with_source_file_name(self, file_name: String) -> Self
pub fn with_source_file_name(self, file_name: String) -> Self
Sets the source file name for atoms created from file uploads
pub fn with_status(self, status: AtomStatus) -> Self
Sourcepub const fn content(&self) -> &Value
pub const fn content(&self) -> &Value
Returns a reference to the Atom’s content.
This method provides read-only access to the stored data, maintaining the immutability principle.
pub fn set_status(&mut self, status: AtomStatus)
Sourcepub fn get_transformed_content(&self, transform: &str) -> Value
pub fn get_transformed_content(&self, transform: &str) -> Value
Applies a transformation to the Atom’s content and returns the result.
Currently supports:
- “lowercase”: Converts string content to lowercase
If the transformation is not recognized or cannot be applied, returns a clone of the original content.
§Arguments
transform- The name of the transformation to apply
Sourcepub fn uuid(&self) -> &str
pub fn uuid(&self) -> &str
Returns the unique identifier of this Atom.
This UUID uniquely identifies this specific version of the data and is used by Molecules to point to the current version.
Sourcepub fn source_schema_name(&self) -> &str
pub fn source_schema_name(&self) -> &str
Returns the name of the schema that defines this Atom’s structure.
The schema name is used to validate the content structure and determine applicable permissions and payment requirements.
Sourcepub fn source_pub_key(&self) -> &str
pub fn source_pub_key(&self) -> &str
Returns the public key of the entity that created this Atom.
This is used for authentication and permission validation when accessing or modifying the data.
Sourcepub fn source_file_name(&self) -> Option<&String>
pub fn source_file_name(&self) -> Option<&String>
Returns the original filename if this atom was created from a file upload.
This is used for tracking data provenance and auditing purposes.
Sourcepub const fn created_at(&self) -> DateTime<Utc>
pub const fn created_at(&self) -> DateTime<Utc>
Returns the timestamp when this Atom was created.
This timestamp is used for auditing and version history tracking.
Sourcepub const fn prev_atom_uuid(&self) -> Option<&String>
pub const fn prev_atom_uuid(&self) -> Option<&String>
Returns the UUID of the previous version of this data, if any.
This forms the chain of version history, allowing traversal through all previous versions of the data.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Atom
impl<'de> Deserialize<'de> for Atom
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Atom
impl RefUnwindSafe for Atom
impl Send for Atom
impl Sync for Atom
impl Unpin for Atom
impl UnwindSafe for Atom
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more