aboutsummaryrefslogtreecommitdiff
path: root/vendor/log/src/kv/key.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2024-07-19 15:37:58 +0300
committerValentin Popov <valentin@popov.link>2024-07-19 15:37:58 +0300
commita990de90fe41456a23e58bd087d2f107d321f3a1 (patch)
tree15afc392522a9e85dc3332235e311b7d39352ea9 /vendor/log/src/kv/key.rs
parent3d48cd3f81164bbfc1a755dc1d4a9a02f98c8ddd (diff)
downloadfparkan-a990de90fe41456a23e58bd087d2f107d321f3a1.tar.xz
fparkan-a990de90fe41456a23e58bd087d2f107d321f3a1.zip
Deleted vendor folder
Diffstat (limited to 'vendor/log/src/kv/key.rs')
-rw-r--r--vendor/log/src/kv/key.rs157
1 files changed, 0 insertions, 157 deletions
diff --git a/vendor/log/src/kv/key.rs b/vendor/log/src/kv/key.rs
deleted file mode 100644
index 4f9a506..0000000
--- a/vendor/log/src/kv/key.rs
+++ /dev/null
@@ -1,157 +0,0 @@
-//! Structured keys.
-
-use std::borrow::Borrow;
-use std::fmt;
-
-/// A type that can be converted into a [`Key`](struct.Key.html).
-pub trait ToKey {
- /// Perform the conversion.
- fn to_key(&self) -> Key;
-}
-
-impl<'a, T> ToKey for &'a T
-where
- T: ToKey + ?Sized,
-{
- fn to_key(&self) -> Key {
- (**self).to_key()
- }
-}
-
-impl<'k> ToKey for Key<'k> {
- fn to_key(&self) -> Key {
- Key { key: self.key }
- }
-}
-
-impl ToKey for str {
- fn to_key(&self) -> Key {
- Key::from_str(self)
- }
-}
-
-/// A key in a structured key-value pair.
-// These impls must only be based on the as_str() representation of the key
-// If a new field (such as an optional index) is added to the key they must not affect comparison
-#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
-pub struct Key<'k> {
- key: &'k str,
-}
-
-impl<'k> Key<'k> {
- /// Get a key from a borrowed string.
- pub fn from_str(key: &'k str) -> Self {
- Key { key }
- }
-
- /// Get a borrowed string from this key.
- pub fn as_str(&self) -> &str {
- self.key
- }
-
- /// Try get a string borrowed for the `'k` lifetime from this key.
- pub fn to_borrowed_str(&self) -> Option<&'k str> {
- // NOTE: This API leaves room for keys to be owned
- Some(self.key)
- }
-}
-
-impl<'k> fmt::Display for Key<'k> {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- self.key.fmt(f)
- }
-}
-
-impl<'k> AsRef<str> for Key<'k> {
- fn as_ref(&self) -> &str {
- self.as_str()
- }
-}
-
-impl<'k> Borrow<str> for Key<'k> {
- fn borrow(&self) -> &str {
- self.as_str()
- }
-}
-
-impl<'k> From<&'k str> for Key<'k> {
- fn from(s: &'k str) -> Self {
- Key::from_str(s)
- }
-}
-
-#[cfg(feature = "std")]
-mod std_support {
- use super::*;
-
- use std::borrow::Cow;
-
- impl ToKey for String {
- fn to_key(&self) -> Key {
- Key::from_str(self)
- }
- }
-
- impl<'a> ToKey for Cow<'a, str> {
- fn to_key(&self) -> Key {
- Key::from_str(self)
- }
- }
-}
-
-#[cfg(feature = "kv_unstable_sval")]
-mod sval_support {
- use super::*;
-
- extern crate sval;
- extern crate sval_ref;
-
- use self::sval::Value;
- use self::sval_ref::ValueRef;
-
- impl<'a> Value for Key<'a> {
- fn stream<'sval, S: sval::Stream<'sval> + ?Sized>(
- &'sval self,
- stream: &mut S,
- ) -> sval::Result {
- self.key.stream(stream)
- }
- }
-
- impl<'a> ValueRef<'a> for Key<'a> {
- fn stream_ref<S: self::sval::Stream<'a> + ?Sized>(
- &self,
- stream: &mut S,
- ) -> self::sval::Result {
- self.key.stream(stream)
- }
- }
-}
-
-#[cfg(feature = "kv_unstable_serde")]
-mod serde_support {
- use super::*;
-
- extern crate serde;
-
- use self::serde::{Serialize, Serializer};
-
- impl<'a> Serialize for Key<'a> {
- fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
- where
- S: Serializer,
- {
- self.key.serialize(serializer)
- }
- }
-}
-
-#[cfg(test)]
-mod tests {
- use super::*;
-
- #[test]
- fn key_from_string() {
- assert_eq!("a key", Key::from_str("a key").as_str());
- }
-}