unobtanium 3.0.0

Opinioated Web search engine library with crawler and viewer companion.
Documentation

use super::id::NumericDatabseId;

/// Helper to tag numeric ids onto other datastructures for use with the database.
///
/// Use the  [`.with_numeric_id(id)`] for convenient construction.
///
/// This is intentionally not serde compatible to avoid leaking internal Database ids.
/// Use UUIDs for communication with the outside world instead.
///
/// [`.with_numeric_id(id)`]: self::IntoWithNumericId::with_numeric_id
#[derive(Clone)]
pub struct WithNumericId<T, I>
where T: Clone, I: NumericDatabseId {

	/// The numeric id the associated data has in a database.
	pub id: I,

	/// The actual data
	pub data: T,
}

/// Provides a convenient function to add a numeric ID to a datastructure.
pub trait IntoWithNumericId<T, I>
where T: Clone, I: NumericDatabseId {

	/// Convert a datastructure to a [`WithNumericId`][self::WithNumericId] containing it.
	fn with_numeric_id(self, id: I) -> WithNumericId<T, I>;
}

impl<T,I> IntoWithNumericId<T, I> for T
where T: Clone, I: NumericDatabseId {
	fn with_numeric_id(self, id: I) -> WithNumericId<T, I> {
		WithNumericId {
			id: id,
			data: self,
		}
	}
}