#![warn(missing_docs)]
pub mod apply_update;
pub use apply_update::ApplyUpdate;
#[cfg(native)]
pub mod endpoint;
#[cfg(feature = "exception")]
pub mod exception;
#[cfg(feature = "messages")]
pub mod messages;
pub mod model_info {
use std::marker::PhantomData;
pub trait InfoModel {
type PrimaryKey;
}
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
feature = "serde",
serde(bound(
serialize = "T::PrimaryKey: serde::Serialize",
deserialize = "T::PrimaryKey: serde::Deserialize<'de>"
))
)]
pub struct RelationInfo<T: InfoModel> {
pub id: T::PrimaryKey,
#[cfg_attr(feature = "serde", serde(skip))]
_model: PhantomData<T>,
}
impl<T: InfoModel> RelationInfo<T> {
pub const fn new(id: T::PrimaryKey) -> Self {
Self {
id,
_model: PhantomData,
}
}
pub const fn id(&self) -> &T::PrimaryKey {
&self.id
}
pub fn into_id(self) -> T::PrimaryKey {
self.id
}
}
impl<T> std::fmt::Debug for RelationInfo<T>
where
T: InfoModel,
T::PrimaryKey: std::fmt::Debug,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("RelationInfo")
.field("id", &self.id)
.finish()
}
}
impl<T> Clone for RelationInfo<T>
where
T: InfoModel,
T::PrimaryKey: Clone,
{
fn clone(&self) -> Self {
Self::new(self.id.clone())
}
}
impl<T> PartialEq for RelationInfo<T>
where
T: InfoModel,
T::PrimaryKey: PartialEq,
{
fn eq(&self, other: &Self) -> bool {
self.id == other.id
}
}
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
feature = "serde",
serde(bound(
serialize = "Target::PrimaryKey: serde::Serialize",
deserialize = "Target::PrimaryKey: serde::Deserialize<'de>"
))
)]
pub struct ManyToManyInfo<Source, Target: InfoModel> {
pub target_ids: Vec<Target::PrimaryKey>,
#[cfg_attr(feature = "serde", serde(skip))]
_source: PhantomData<Source>,
}
impl<Source, Target> ManyToManyInfo<Source, Target>
where
Target: InfoModel,
{
pub fn new<I>(target_ids: I) -> Self
where
I: IntoIterator<Item = Target::PrimaryKey>,
{
Self {
target_ids: target_ids.into_iter().collect(),
_source: PhantomData,
}
}
pub const fn empty() -> Self {
Self {
target_ids: Vec::new(),
_source: PhantomData,
}
}
pub fn target_ids(&self) -> &[Target::PrimaryKey] {
&self.target_ids
}
pub fn into_target_ids(self) -> Vec<Target::PrimaryKey> {
self.target_ids
}
}
impl<Source, Target> Default for ManyToManyInfo<Source, Target>
where
Target: InfoModel,
{
fn default() -> Self {
Self::empty()
}
}
impl<Source, Target> std::fmt::Debug for ManyToManyInfo<Source, Target>
where
Target: InfoModel,
Target::PrimaryKey: std::fmt::Debug,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ManyToManyInfo")
.field("target_ids", &self.target_ids)
.finish()
}
}
impl<Source, Target> Clone for ManyToManyInfo<Source, Target>
where
Target: InfoModel,
Target::PrimaryKey: Clone,
{
fn clone(&self) -> Self {
Self::new(self.target_ids.clone())
}
}
impl<Source, Target> PartialEq for ManyToManyInfo<Source, Target>
where
Target: InfoModel,
Target::PrimaryKey: PartialEq,
{
fn eq(&self, other: &Self) -> bool {
self.target_ids == other.target_ids
}
}
#[cfg(test)]
mod tests {
use super::{InfoModel, ManyToManyInfo, RelationInfo};
#[derive(Debug)]
struct Post;
impl InfoModel for Post {
type PrimaryKey = i64;
}
#[test]
fn relation_info_preserves_primary_key() {
let relation = RelationInfo::<Post>::new(7);
assert_eq!(*relation.id(), 7);
assert_eq!(relation.into_id(), 7);
}
#[test]
fn many_to_many_info_preserves_target_ids() {
let info = ManyToManyInfo::<(), Post>::new([1, 2, 3]);
assert_eq!(info.target_ids(), &[1, 2, 3]);
}
}
}
#[cfg(feature = "negotiation")]
pub mod negotiation;
#[cfg(feature = "pagination")]
pub mod pagination;
#[cfg(feature = "parsers")]
pub mod parsers;
pub mod rate_limit;
#[cfg(feature = "reactive")]
pub mod reactive;
#[cfg(feature = "security")]
pub mod security;
#[cfg(feature = "serializers")]
pub mod serializers;
#[cfg(feature = "signals")]
pub mod signals;
#[cfg(feature = "types")]
pub mod types;
#[cfg(feature = "validators")]
pub mod validators;
#[cfg(native)]
pub mod ws;
#[cfg(all(feature = "types", feature = "page"))]
pub use crate::types::page;
#[cfg(feature = "macros")]
pub use reinhardt_macros as macros;
pub use crate::rate_limit::RateLimitStrategy;
pub use async_trait::async_trait;
#[cfg(native)]
pub use tokio;
#[cfg(feature = "serde")]
pub mod serde {
pub use ::serde::{Deserialize, Deserializer, Serialize, Serializer, de, ser};
pub use ::serde_json as json;
}