Struct aragog::EdgeRecord

source ·
pub struct EdgeRecord<T> {
    pub data: T,
    /* private fields */
}
Expand description

Struct wrapping an edge document, with the from and to fields correctly set.

The document of type T mut implement Record and EdgeRecord also implements it.

Note

EdgeRecord implements Deref and DerefMut into T

Fields§

§data: T

The main document data, must implement Record.

Note: The data is flattened on save, so you won’t have any field named data in your database.

Implementations§

source§

impl<T: Record> EdgeRecord<T>

source

pub fn new(id_from: String, id_to: String, data: T) -> Result<Self, Error>

Manually instantiates an Edge record

Arguments
  • id_from - The from document id
  • id_to - The to document id
  • data - The main document data
Errors

This function validates the format of the id fields which can result in an error.

source

pub async fn from_record<D, R>( &self, db_access: &D ) -> Result<DatabaseRecord<R>, Error>where D: DatabaseAccess + ?Sized, R: Record,

Retrieves the from document from the database

source

pub async fn to_record<D, R>( &self, db_access: &D ) -> Result<DatabaseRecord<R>, Error>where D: DatabaseAccess + ?Sized, R: Record,

Retrieves the to document from the database

source

pub fn id_from(&self) -> &String

Retrieves the document _from field, storing the target documents id.

source

pub fn id_to(&self) -> &String

Retrieves the document _to field, storing the target documents id.

source

pub fn key_from(&self) -> &str

Parses the from value to retrieve only the _key part.

Panics

This method may panic if the from value is not formatted correctly.

source

pub fn key_to(&self) -> &str

Parses the to value to retrieve only the _key part.

Panics

This method may panic if the to value is not formatted correctly.

source

pub fn to_collection_name(&self) -> String

Parses the from value to retrieve only the collection name part.

Panics

This method may panic if the to value is not formatted correctly.

source

pub fn from_collection_name(&self) -> &str

Parses the to value to retrieve only the collection name part.

Panics

This method may panic if the from value is not formatted correctly.

Trait Implementations§

source§

impl<T: Clone> Clone for EdgeRecord<T>

source§

fn clone(&self) -> EdgeRecord<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Record> Deref for EdgeRecord<T>

§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<T: Record> DerefMut for EdgeRecord<T>

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

impl<'de, T> Deserialize<'de> for EdgeRecord<T>where T: Deserialize<'de>,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<T: Record + Send> Record for EdgeRecord<T>

source§

const COLLECTION_NAME: &'static str = T::COLLECTION_NAME

returns the associated Collection for read and write operations.
source§

fn before_create_hook<'life0, 'life1, 'async_trait, D>( &'life0 mut self, db_accessor: &'life1 D ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where D: DatabaseAccess + ?Sized + 'async_trait, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

method called by DatabaseRecord::create before the database operation. Read more
source§

fn before_save_hook<'life0, 'life1, 'async_trait, D>( &'life0 mut self, db_accessor: &'life1 D ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where D: DatabaseAccess + ?Sized + 'async_trait, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

method called by DatabaseRecord::save before the database operation. Read more
source§

fn before_delete_hook<'life0, 'life1, 'async_trait, D>( &'life0 mut self, db_accessor: &'life1 D ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where D: DatabaseAccess + ?Sized + 'async_trait, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

method called by DatabaseRecord::delete before the database operation. Read more
source§

fn after_create_hook<'life0, 'life1, 'async_trait, D>( &'life0 mut self, db_accessor: &'life1 D ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where D: DatabaseAccess + ?Sized + 'async_trait, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

method called automatically by DatabaseRecord::create after the database operation. Read more
source§

fn after_save_hook<'life0, 'life1, 'async_trait, D>( &'life0 mut self, db_accessor: &'life1 D ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where D: DatabaseAccess + ?Sized + 'async_trait, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

method called automatically by DatabaseRecord::save after the database operation. Read more
source§

fn after_delete_hook<'life0, 'life1, 'async_trait, D>( &'life0 mut self, db_accessor: &'life1 D ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>where D: DatabaseAccess + ?Sized + 'async_trait, Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

method called automatically by DatabaseRecord::delete after the database operation. Read more
source§

fn find<'life0, 'life1, 'async_trait, D>( key: &'life0 str, db_accessor: &'life1 D ) -> Pin<Box<dyn Future<Output = Result<DatabaseRecord<Self>, Error>> + Send + 'async_trait>>where D: DatabaseAccess + ?Sized + 'async_trait, Self: Send + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Finds a document in database from its unique key. Simple wrapper for DatabaseRecord<T>::find
source§

fn get<'life0, 'life1, 'async_trait, D>( query: &'life0 Query, db_accessor: &'life1 D ) -> Pin<Box<dyn Future<Output = Result<QueryResult<Self>, Error>> + Send + 'async_trait>>where D: DatabaseAccess + ?Sized + 'async_trait, Self: Send + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Finds all documents in database matching a Query. Simple wrapper for DatabaseRecord<T>::get
source§

fn get_in_batches<'life0, 'life1, 'async_trait, D>( query: &'life0 Query, db_accessor: &'life1 D, batch_size: u32 ) -> Pin<Box<dyn Future<Output = Result<QueryCursor<Self>, Error>> + Send + 'async_trait>>where D: DatabaseAccess + ?Sized + 'async_trait, Self: Send + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Finds all documents in database matching a Query in batches. Simple wrapper for DatabaseRecord<T>::get_in_batches
source§

fn exists<'life0, 'life1, 'async_trait, D>( query: &'life0 Query, db_accessor: &'life1 D ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where D: DatabaseAccess + ?Sized + 'async_trait, Self: Send + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Returns true if there are any document in database matching a Query. Simple wrapper for DatabaseRecord<T>::exists
source§

fn create<'life0, 'async_trait, D>( record: Self, db_accessor: &'life0 D ) -> Pin<Box<dyn Future<Output = Result<DatabaseRecord<Self>, Error>> + Send + 'async_trait>>where D: DatabaseAccess + ?Sized + 'async_trait, Self: Send + 'async_trait, 'life0: 'async_trait,

Creates a new document in database. Simple wrapper for DatabaseRecord<T>::create Read more
source§

fn query() -> Query

Creates a new Query instance for Self. Read more
source§

fn transaction_builder() -> TransactionBuilder

Returns a transaction builder on this collection only.
source§

fn transaction<'life0, 'async_trait>( db_connection: &'life0 DatabaseConnection ) -> Pin<Box<dyn Future<Output = Result<Transaction, Error>> + Send + 'async_trait>>where Self: Send + 'async_trait, 'life0: 'async_trait,

Builds a transaction for this collection only. Read more
source§

impl<T> Serialize for EdgeRecord<T>where T: Serialize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<T: Record> Validate for EdgeRecord<T>

source§

fn validations(&self, errors: &mut Vec<String>)

Runs all the defined validation on fields and fills the errors string vector with custom error messages
source§

fn validate(&self) -> Result<(), Error>

Validates the object field formats, logic or anything. Read more
source§

fn is_valid(&self) -> bool

Runs all validations and returns a false if they failed, on success true is returned
source§

fn validate_field_presence<T>( field_name: &str, field: &Option<T>, errors: &mut Vec<String> ) -> bool

Helper function to simply check the presence of a field. This function is usually used inside the validations method since it will fill the errors with a message if the field is missing. Read more
source§

fn validate_field_absence<T>( field_name: &str, field: &Option<T>, errors: &mut Vec<String> ) -> bool

Helper function to simply check the absence of a field. This function is usually used inside the validations method since it will fill the errors with a message if the field is missing. Read more
source§

fn validate_numeric_string( field_path: &str, str: &str, errors: &mut Vec<String> ) -> bool

Validates that str is numeric. Usually used as a helper function for implementations of Validate trait. Read more
source§

fn validate_max_len( field_path: &str, str: &str, max_len: usize, errors: &mut Vec<String> ) -> bool

Validates that str is not longer than expected. Usually used as a helper function for implementations of Validate trait. Read more
source§

fn validate_min_len( field_path: &str, str: &str, min_len: usize, errors: &mut Vec<String> ) -> bool

Validates that str is not shorter than expected. Usually used as a helper function for implementations of Validate trait. Read more
source§

fn validate_len( field_path: &str, str: &str, len: usize, errors: &mut Vec<String> ) -> bool

Validates that str has the exact expected length. Usually used as a helper function for implementations of Validate trait. Read more
source§

fn validate_max_count<T>( field_path: &str, field_value: Iter<'_, T>, max_count: usize, errors: &mut Vec<String> ) -> bool

Validates the maximum number of elements in field_value. Usually used as a helper function for implementations of Validate trait. Read more
source§

fn validate_min_count<T>( field_path: &str, field_value: Iter<'_, T>, min_count: usize, errors: &mut Vec<String> ) -> bool

Validates the minimum number of elements in field_value. Usually used as a helper function for implementations of Validate trait. Read more
source§

fn validate_count<T>( field_path: &str, field_value: Iter<'_, T>, count: usize, errors: &mut Vec<String> ) -> bool

Validates the exact number of elements in field_value. Usually used as a helper function for implementations of Validate trait. Read more
source§

fn validate_regex( field_path: &str, str: &str, regex: &str, errors: &mut Vec<String> ) -> bool

Validates that str matches a regexp. Usually used as a helper function for implementations of Validate trait. Read more
source§

fn validate_greater_than<T: PartialOrd + Display>( field_path: &str, value: T, min_value: T, errors: &mut Vec<String> ) -> bool

Validates that value is greater than min_value. Usually used as a helper function for implementations of Validate trait. Read more
source§

fn validate_greater_or_equal_to<T: PartialOrd + Display>( field_path: &str, value: T, min_value: T, errors: &mut Vec<String> ) -> bool

Validates that value is greater or equal to min_value. Usually used as a helper function for implementations of Validate trait. Read more
source§

fn validate_lesser_than<T: PartialOrd + Display>( field_path: &str, value: T, max_value: T, errors: &mut Vec<String> ) -> bool

Validates that value is lower than max_value. Usually used as a helper function for implementations of Validate trait. Read more
source§

fn validate_lesser_or_equal_to<T: PartialOrd + Display>( field_path: &str, value: T, max_value: T, errors: &mut Vec<String> ) -> bool

Validates that value is lower or equal to max_value. Usually used as a helper function for implementations of Validate trait. Read more
source§

const SIMPLE_EMAIL_REGEX: &'static str = r#"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}"#

A simple and fast regular expression to validate email formats
source§

const RFC_5322_EMAIL_REGEX: &'static str = r#"(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])"#

RFC 5322 compliant regular expression to validate email formats from emailregex.com. It is significantly slower than the simple_email_regex

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for EdgeRecord<T>where T: RefUnwindSafe,

§

impl<T> Send for EdgeRecord<T>where T: Send,

§

impl<T> Sync for EdgeRecord<T>where T: Sync,

§

impl<T> Unpin for EdgeRecord<T>where T: Unpin,

§

impl<T> UnwindSafe for EdgeRecord<T>where T: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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.

§

impl<T> Instrument for T

§

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

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

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 Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,