mirror of
https://github.com/Cuprate/cuprate.git
synced 2024-12-23 03:59:31 +00:00
epee: unseal trait EpeeValue
(#184)
* unseal `trait EpeeValue` * fix `container_as_blob.rs` * clippy * epee-encoding: remove `sealed`
This commit is contained in:
parent
b76042a4e4
commit
bef2a2cbd4
4 changed files with 8 additions and 47 deletions
21
Cargo.lock
generated
21
Cargo.lock
generated
|
@ -341,7 +341,7 @@ version = "4.5.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c780290ccf4fb26629baa7a1081e68ced113f1d3ec302fa5948f1c381ebf06c6"
|
checksum = "c780290ccf4fb26629baa7a1081e68ced113f1d3ec302fa5948f1c381ebf06c6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"heck 0.5.0",
|
"heck",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.66",
|
"syn 2.0.66",
|
||||||
|
@ -815,7 +815,6 @@ dependencies = [
|
||||||
"hex",
|
"hex",
|
||||||
"paste",
|
"paste",
|
||||||
"ref-cast",
|
"ref-cast",
|
||||||
"sealed",
|
|
||||||
"thiserror",
|
"thiserror",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -1062,12 +1061,6 @@ dependencies = [
|
||||||
"num-traits",
|
"num-traits",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "heck"
|
|
||||||
version = "0.4.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "heck"
|
name = "heck"
|
||||||
version = "0.5.0"
|
version = "0.5.0"
|
||||||
|
@ -2161,18 +2154,6 @@ version = "1.2.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "sealed"
|
|
||||||
version = "0.5.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f4a8caec23b7800fb97971a1c6ae365b6239aaeddfb934d6265f8505e795699d"
|
|
||||||
dependencies = [
|
|
||||||
"heck 0.4.1",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 2.0.66",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "security-framework"
|
name = "security-framework"
|
||||||
version = "2.11.0"
|
version = "2.11.0"
|
||||||
|
|
|
@ -17,7 +17,6 @@ std = ["dep:thiserror", "bytes/std", "fixed-bytes/std"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
fixed-bytes = { path = "../fixed-bytes", default-features = false }
|
fixed-bytes = { path = "../fixed-bytes", default-features = false }
|
||||||
|
|
||||||
sealed = "0.5.0"
|
|
||||||
paste = "1.0.14"
|
paste = "1.0.14"
|
||||||
ref-cast = "1.0.22"
|
ref-cast = "1.0.22"
|
||||||
bytes = { workspace = true }
|
bytes = { workspace = true }
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
use bytes::{Buf, BufMut, Bytes, BytesMut};
|
use bytes::{Buf, BufMut, Bytes, BytesMut};
|
||||||
use ref_cast::RefCast;
|
use ref_cast::RefCast;
|
||||||
use sealed::sealed;
|
|
||||||
|
|
||||||
use crate::{error::*, value::*, EpeeValue, InnerMarker, Marker};
|
use crate::{error::*, EpeeValue, InnerMarker, Marker};
|
||||||
|
|
||||||
#[derive(RefCast)]
|
#[derive(RefCast)]
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
|
@ -26,7 +25,6 @@ impl<'a, T: Containerable + EpeeValue> From<&'a Vec<T>> for &'a ContainerAsBlob<
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[sealed]
|
|
||||||
impl<T: Containerable + EpeeValue> EpeeValue for ContainerAsBlob<T> {
|
impl<T: Containerable + EpeeValue> EpeeValue for ContainerAsBlob<T> {
|
||||||
const MARKER: Marker = Marker::new(InnerMarker::String);
|
const MARKER: Marker = Marker::new(InnerMarker::String);
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
|
//! This module contains a [`EpeeValue`] trait and
|
||||||
|
//! impls for some possible base epee values.
|
||||||
|
|
||||||
use alloc::{string::String, vec::Vec};
|
use alloc::{string::String, vec::Vec};
|
||||||
/// This module contains a `sealed` [`EpeeValue`] trait and different impls for
|
|
||||||
/// the different possible base epee values.
|
|
||||||
use core::fmt::Debug;
|
use core::fmt::Debug;
|
||||||
|
|
||||||
use bytes::{Buf, BufMut, Bytes, BytesMut};
|
use bytes::{Buf, BufMut, Bytes, BytesMut};
|
||||||
use sealed::sealed;
|
|
||||||
|
|
||||||
use fixed_bytes::{ByteArray, ByteArrayVec};
|
use fixed_bytes::{ByteArray, ByteArrayVec};
|
||||||
|
|
||||||
|
@ -12,10 +12,9 @@ use crate::{
|
||||||
io::*, varint::*, EpeeObject, Error, InnerMarker, Marker, Result, MAX_STRING_LEN_POSSIBLE,
|
io::*, varint::*, EpeeObject, Error, InnerMarker, Marker, Result, MAX_STRING_LEN_POSSIBLE,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A trait for epee values, this trait is sealed as all possible epee values are
|
/// A trait for epee values.
|
||||||
/// defined in the lib, to make an [`EpeeValue`] outside the lib you will need to
|
///
|
||||||
/// use the trait [`EpeeObject`].
|
/// All [`EpeeObject`] objects automatically implement [`EpeeValue`].
|
||||||
#[sealed(pub(crate))]
|
|
||||||
pub trait EpeeValue: Sized {
|
pub trait EpeeValue: Sized {
|
||||||
const MARKER: Marker;
|
const MARKER: Marker;
|
||||||
|
|
||||||
|
@ -37,7 +36,6 @@ pub trait EpeeValue: Sized {
|
||||||
fn write<B: BufMut>(self, w: &mut B) -> Result<()>;
|
fn write<B: BufMut>(self, w: &mut B) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[sealed]
|
|
||||||
impl<T: EpeeObject> EpeeValue for T {
|
impl<T: EpeeObject> EpeeValue for T {
|
||||||
const MARKER: Marker = Marker::new(InnerMarker::Object);
|
const MARKER: Marker = Marker::new(InnerMarker::Object);
|
||||||
|
|
||||||
|
@ -56,7 +54,6 @@ impl<T: EpeeObject> EpeeValue for T {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[sealed]
|
|
||||||
impl<T: EpeeObject> EpeeValue for Vec<T> {
|
impl<T: EpeeObject> EpeeValue for Vec<T> {
|
||||||
const MARKER: Marker = T::MARKER.into_seq();
|
const MARKER: Marker = T::MARKER.into_seq();
|
||||||
|
|
||||||
|
@ -94,7 +91,6 @@ impl<T: EpeeObject> EpeeValue for Vec<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[sealed]
|
|
||||||
impl<T: EpeeObject + Debug, const N: usize> EpeeValue for [T; N] {
|
impl<T: EpeeObject + Debug, const N: usize> EpeeValue for [T; N] {
|
||||||
const MARKER: Marker = <T>::MARKER.into_seq();
|
const MARKER: Marker = <T>::MARKER.into_seq();
|
||||||
|
|
||||||
|
@ -119,7 +115,6 @@ impl<T: EpeeObject + Debug, const N: usize> EpeeValue for [T; N] {
|
||||||
|
|
||||||
macro_rules! epee_numb {
|
macro_rules! epee_numb {
|
||||||
($numb:ty, $marker:ident, $read_fn:ident, $write_fn:ident) => {
|
($numb:ty, $marker:ident, $read_fn:ident, $write_fn:ident) => {
|
||||||
#[sealed]
|
|
||||||
impl EpeeValue for $numb {
|
impl EpeeValue for $numb {
|
||||||
const MARKER: Marker = Marker::new(InnerMarker::$marker);
|
const MARKER: Marker = Marker::new(InnerMarker::$marker);
|
||||||
|
|
||||||
|
@ -148,7 +143,6 @@ epee_numb!(u32, U32, get_u32_le, put_u32_le);
|
||||||
epee_numb!(u64, U64, get_u64_le, put_u64_le);
|
epee_numb!(u64, U64, get_u64_le, put_u64_le);
|
||||||
epee_numb!(f64, F64, get_f64_le, put_f64_le);
|
epee_numb!(f64, F64, get_f64_le, put_f64_le);
|
||||||
|
|
||||||
#[sealed]
|
|
||||||
impl EpeeValue for bool {
|
impl EpeeValue for bool {
|
||||||
const MARKER: Marker = Marker::new(InnerMarker::Bool);
|
const MARKER: Marker = Marker::new(InnerMarker::Bool);
|
||||||
|
|
||||||
|
@ -165,7 +159,6 @@ impl EpeeValue for bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[sealed]
|
|
||||||
impl EpeeValue for Vec<u8> {
|
impl EpeeValue for Vec<u8> {
|
||||||
const MARKER: Marker = Marker::new(InnerMarker::String);
|
const MARKER: Marker = Marker::new(InnerMarker::String);
|
||||||
|
|
||||||
|
@ -209,7 +202,6 @@ impl EpeeValue for Vec<u8> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[sealed::sealed]
|
|
||||||
impl EpeeValue for Bytes {
|
impl EpeeValue for Bytes {
|
||||||
const MARKER: Marker = Marker::new(InnerMarker::String);
|
const MARKER: Marker = Marker::new(InnerMarker::String);
|
||||||
|
|
||||||
|
@ -250,7 +242,6 @@ impl EpeeValue for Bytes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[sealed::sealed]
|
|
||||||
impl EpeeValue for BytesMut {
|
impl EpeeValue for BytesMut {
|
||||||
const MARKER: Marker = Marker::new(InnerMarker::String);
|
const MARKER: Marker = Marker::new(InnerMarker::String);
|
||||||
|
|
||||||
|
@ -294,7 +285,6 @@ impl EpeeValue for BytesMut {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[sealed::sealed]
|
|
||||||
impl<const N: usize> EpeeValue for ByteArrayVec<N> {
|
impl<const N: usize> EpeeValue for ByteArrayVec<N> {
|
||||||
const MARKER: Marker = Marker::new(InnerMarker::String);
|
const MARKER: Marker = Marker::new(InnerMarker::String);
|
||||||
|
|
||||||
|
@ -338,7 +328,6 @@ impl<const N: usize> EpeeValue for ByteArrayVec<N> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[sealed::sealed]
|
|
||||||
impl<const N: usize> EpeeValue for ByteArray<N> {
|
impl<const N: usize> EpeeValue for ByteArray<N> {
|
||||||
const MARKER: Marker = Marker::new(InnerMarker::String);
|
const MARKER: Marker = Marker::new(InnerMarker::String);
|
||||||
|
|
||||||
|
@ -374,7 +363,6 @@ impl<const N: usize> EpeeValue for ByteArray<N> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[sealed]
|
|
||||||
impl EpeeValue for String {
|
impl EpeeValue for String {
|
||||||
const MARKER: Marker = Marker::new(InnerMarker::String);
|
const MARKER: Marker = Marker::new(InnerMarker::String);
|
||||||
|
|
||||||
|
@ -403,7 +391,6 @@ impl EpeeValue for String {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[sealed]
|
|
||||||
impl<const N: usize> EpeeValue for [u8; N] {
|
impl<const N: usize> EpeeValue for [u8; N] {
|
||||||
const MARKER: Marker = Marker::new(InnerMarker::String);
|
const MARKER: Marker = Marker::new(InnerMarker::String);
|
||||||
|
|
||||||
|
@ -429,7 +416,6 @@ impl<const N: usize> EpeeValue for [u8; N] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[sealed]
|
|
||||||
impl<const N: usize> EpeeValue for Vec<[u8; N]> {
|
impl<const N: usize> EpeeValue for Vec<[u8; N]> {
|
||||||
const MARKER: Marker = <[u8; N]>::MARKER.into_seq();
|
const MARKER: Marker = <[u8; N]>::MARKER.into_seq();
|
||||||
|
|
||||||
|
@ -470,7 +456,6 @@ impl<const N: usize> EpeeValue for Vec<[u8; N]> {
|
||||||
|
|
||||||
macro_rules! epee_seq {
|
macro_rules! epee_seq {
|
||||||
($val:ty) => {
|
($val:ty) => {
|
||||||
#[sealed]
|
|
||||||
impl EpeeValue for Vec<$val> {
|
impl EpeeValue for Vec<$val> {
|
||||||
const MARKER: Marker = <$val>::MARKER.into_seq();
|
const MARKER: Marker = <$val>::MARKER.into_seq();
|
||||||
|
|
||||||
|
@ -509,7 +494,6 @@ macro_rules! epee_seq {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[sealed]
|
|
||||||
impl<const N: usize> EpeeValue for [$val; N] {
|
impl<const N: usize> EpeeValue for [$val; N] {
|
||||||
const MARKER: Marker = <$val>::MARKER.into_seq();
|
const MARKER: Marker = <$val>::MARKER.into_seq();
|
||||||
|
|
||||||
|
@ -548,7 +532,6 @@ epee_seq!(String);
|
||||||
epee_seq!(Bytes);
|
epee_seq!(Bytes);
|
||||||
epee_seq!(BytesMut);
|
epee_seq!(BytesMut);
|
||||||
|
|
||||||
#[sealed]
|
|
||||||
impl<T: EpeeValue> EpeeValue for Option<T> {
|
impl<T: EpeeValue> EpeeValue for Option<T> {
|
||||||
const MARKER: Marker = T::MARKER;
|
const MARKER: Marker = T::MARKER;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue