This commit is contained in:
JMARyA 2024-09-13 14:00:28 +02:00
parent 949340a7f2
commit b0bae64efc
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
3 changed files with 10 additions and 10 deletions

2
Cargo.lock generated
View file

@ -707,7 +707,7 @@ dependencies = [
[[package]]
name = "mongod"
version = "0.2.1"
version = "0.2.2"
dependencies = [
"chrono",
"futures",

View file

@ -1,6 +1,6 @@
[package]
name = "mongod"
version = "0.2.1"
version = "0.2.2"
edition = "2021"
[features]

View file

@ -10,9 +10,14 @@ use super::{valid::Validate, Model};
pub struct Reference(String);
impl Reference {
/// Create a new reference from String
pub async fn new_raw(reference: &str) -> Option<Self> {
let r = Self(reference.to_string());
/// Create a new reference from String without checks
pub fn new_raw(reference: &str) -> Self {
Self(reference.to_string())
}
/// Create a new reference
pub async fn new(model: &str, id: &str) -> Option<Self> {
let r = Self(format!("{model}::{id}"));
if r.validate().await.is_ok() {
Some(r)
} else {
@ -20,11 +25,6 @@ impl Reference {
}
}
/// Create a new reference
pub async fn new(model: &str, id: &str) -> Option<Self> {
Self::new_raw(&format!("{model}::{id}")).await
}
/// Get just the ID of the referenced `Model`
pub fn id(&self) -> &str {
self.0.split_once("::").unwrap().1