User avatar
ava@soon39c3:~cursor_blinkingverifiedlesbian @star@amazonawaws.com
3w
low-context rust code i like rust. "hm i want people to only be able to create a Valid<T> using the proper way, and not by manually instantiating the struct or smth; but the validation function has to be implementation specific........ how?"
pub trait Validate<T: Debug> {
        /// Validate the type `T` using the given validation_function.
        async fn validate<F>(
            maybe_db: Option<&Database>,
            to_validate: T,
            at_time: DateTime<Utc>,
            validation_function: F,
        ) -> Result<Valid<T>, Error>
        where
            F: AsyncFnOnce(Option<&Database>, &T, &DateTime<Utc>) -> Result<(), Error>,
        {
            validation_function(maybe_db, &to_validate, &at_time).await?;
            Ok(Valid { t: to_validate, at: at_time })
        }
    }

#[derive(Debug)]
    pub struct Valid<T: Debug> {
        /// The type marked as valid
        pub t: T,
        /// The point in time at which the validity of this type has been
        /// checked and established. This is important information, since an
        /// ID-Cert could theoretically get manually invalidated just one second
        /// after a server has established its validity. Validity is therefore
        /// not an eternal property, but sensitive to the context of time.
        at: DateTime<Utc>,
    }