Commit d4180597 authored by Thomas Mühlbacher's avatar Thomas Mühlbacher
Browse files

zv: Assert auto trait impls for pub items

Closes #140.
parent 29e74e86
......@@ -24,6 +24,7 @@ arrayvec = { version = "0.5.1", features = ["serde"], optional = true }
enumflags2 = { version = "0.6.4", features = ["serde"], optional = true }
zvariant_derive = { version = "=2.6.0", path = "../zvariant_derive" }
serde_bytes = { version = "0.11", optional = true }
static_assertions = "1.1.0"
[dev-dependencies]
serde_json = "1.0"
......
use serde::ser::{Serialize, SerializeSeq, Serializer};
use static_assertions::assert_impl_all;
use std::convert::TryFrom;
use crate::{Error, Result, Signature, Type, Value};
......@@ -16,6 +17,8 @@ pub struct Array<'a> {
signature: Signature<'a>,
}
assert_impl_all!(Array<'_>: Send, Sync, Unpin);
impl<'a> Array<'a> {
/// Create a new empty `Array`, given the signature of the elements.
pub fn new(element_signature: Signature<'_>) -> Array<'_> {
......
use core::convert::TryFrom;
use serde::de::{self, DeserializeSeed, EnumAccess, MapAccess, SeqAccess, Visitor};
use static_assertions::assert_impl_all;
use std::{marker::PhantomData, os::unix::io::RawFd, str};
......@@ -13,6 +14,8 @@ use crate::{
#[derive(Debug)]
pub struct Deserializer<'de, 'sig, 'f, B>(pub(crate) crate::DeserializerCommon<'de, 'sig, 'f, B>);
assert_impl_all!(Deserializer<'_, '_, '_, i32>: Send, Sync, Unpin);
impl<'de, 'sig, 'f, B> Deserializer<'de, 'sig, 'f, B>
where
B: byteorder::ByteOrder,
......
use byteorder::WriteBytesExt;
use serde::{ser, ser::SerializeSeq, Serialize};
use static_assertions::assert_impl_all;
use std::{
io::{Seek, Write},
marker::PhantomData,
......@@ -15,6 +16,8 @@ use crate::{
/// Our D-Bus serialization implementation.
pub struct Serializer<'ser, 'sig, B, W>(pub(crate) crate::SerializerCommon<'ser, 'sig, B, W>);
assert_impl_all!(Serializer<'_, '_, i32, i32>: Send, Sync, Unpin);
impl<'ser, 'sig, B, W> Serializer<'ser, 'sig, B, W>
where
B: byteorder::ByteOrder,
......
......@@ -2,6 +2,7 @@ use serde::{
de::{self, DeserializeSeed, VariantAccess, Visitor},
Deserialize,
};
use static_assertions::assert_impl_all;
use std::{marker::PhantomData, os::unix::io::RawFd, str};
......@@ -191,6 +192,8 @@ pub enum Deserializer<'ser, 'sig, 'f, B> {
GVariant(GVDeserializer<'ser, 'sig, 'f, B>),
}
assert_impl_all!(Deserializer<'_, '_, '_, u8>: Send, Sync, Unpin);
impl<'de, 'sig, 'f, B> Deserializer<'de, 'sig, 'f, B>
where
B: byteorder::ByteOrder,
......
......@@ -2,6 +2,7 @@ use core::str;
use std::marker::PhantomData;
use serde::de::{Deserialize, Deserializer, SeqAccess, Visitor};
use static_assertions::assert_impl_all;
use crate::{Signature, Type, Value};
......@@ -27,6 +28,8 @@ pub struct DeserializeValue<'de, T: Type + Deserialize<'de>>(
std::marker::PhantomData<&'de T>,
);
assert_impl_all!(DeserializeValue<'_, i32>: Send, Sync, Unpin);
impl<'de, T: Type + Deserialize<'de>> Deserialize<'de> for DeserializeValue<'de, T> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
......
use std::{collections::HashMap, convert::TryFrom, hash::BuildHasher};
use serde::ser::{Serialize, SerializeSeq, SerializeStruct, Serializer};
use static_assertions::assert_impl_all;
use crate::{Basic, Error, Signature, Type, Value};
......@@ -19,6 +20,8 @@ pub struct Dict<'k, 'v> {
signature: Signature<'k>,
}
assert_impl_all!(Dict<'_, '_>: Send, Sync, Unpin);
impl<'k, 'v> Dict<'k, 'v> {
/// Create a new empty `Dict`, given the signature of the keys and values.
pub fn new(key_signature: Signature<'k>, value_signature: Signature<'v>) -> Self {
......
use std::marker::PhantomData;
use static_assertions::assert_impl_all;
/// The encoding format.
///
#[derive(Debug, PartialEq, Copy, Clone)]
......@@ -12,6 +14,8 @@ pub enum EncodingFormat {
GVariant,
}
assert_impl_all!(EncodingFormat: Send, Sync, Unpin);
impl Default for EncodingFormat {
fn default() -> Self {
EncodingFormat::DBus
......@@ -65,6 +69,8 @@ pub struct EncodingContext<B> {
b: PhantomData<B>,
}
assert_impl_all!(EncodingContext<byteorder::NativeEndian>: Send, Sync, Unpin);
impl<B> EncodingContext<B>
where
B: byteorder::ByteOrder,
......
use serde::{de, ser};
use static_assertions::assert_impl_all;
use std::{convert::Infallible, error, fmt, result};
/// Error type used by zvariant API.
......@@ -26,6 +27,8 @@ pub enum Error {
Infallible,
}
assert_impl_all!(Error: Send, Sync, Unpin);
impl PartialEq for Error {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
......
......@@ -2,6 +2,7 @@
#![allow(deprecated)]
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use static_assertions::assert_impl_all;
use std::os::unix::io;
use crate::{Basic, EncodingFormat, Signature, Type};
......@@ -19,6 +20,8 @@ use crate::{Basic, EncodingFormat, Signature, Type};
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
pub struct Fd(io::RawFd);
assert_impl_all!(Fd: Send, Sync, Unpin);
impl Basic for Fd {
const SIGNATURE_CHAR: char = 'h';
const SIGNATURE_STR: &'static str = "h";
......
use core::convert::TryFrom;
use serde::de::{self, DeserializeSeed, EnumAccess, MapAccess, SeqAccess, Visitor};
use static_assertions::assert_impl_all;
use std::{ffi::CStr, marker::PhantomData, os::unix::io::RawFd, str};
......@@ -14,6 +15,8 @@ use crate::{
#[derive(Debug)]
pub struct Deserializer<'de, 'sig, 'f, B>(pub(crate) crate::DeserializerCommon<'de, 'sig, 'f, B>);
assert_impl_all!(Deserializer<'_, '_,'_, i32>: Send, Sync, Unpin);
impl<'de, 'sig, 'f, B> Deserializer<'de, 'sig, 'f, B>
where
B: byteorder::ByteOrder,
......
use serde::{ser, ser::SerializeSeq, Serialize};
use static_assertions::assert_impl_all;
use std::{
io::{Seek, Write},
marker::PhantomData,
......@@ -15,6 +16,8 @@ use crate::{
/// Our serialization implementation.
pub struct Serializer<'ser, 'sig, B, W>(pub(crate) crate::SerializerCommon<'ser, 'sig, B, W>);
assert_impl_all!(Serializer<'_, '_, i32, i32>: Send, Sync, Unpin);
impl<'ser, 'sig, B, W> Serializer<'ser, 'sig, B, W>
where
B: byteorder::ByteOrder,
......
use serde::ser::{Serialize, Serializer};
use static_assertions::assert_impl_all;
use std::convert::TryFrom;
use crate::{Error, Signature, Type, Value};
......@@ -15,6 +16,8 @@ pub struct Maybe<'a> {
signature: Signature<'a>,
}
assert_impl_all!(Maybe<'_>: Send, Sync, Unpin);
impl<'a> Maybe<'a> {
/// Get a reference to underlying value.
pub fn inner(&self) -> &Option<Value<'a>> {
......
......@@ -6,6 +6,7 @@ use serde::{
de::{Deserialize, Deserializer, Visitor},
ser::{Serialize, Serializer},
};
use static_assertions::assert_impl_all;
use std::borrow::Cow;
use crate::{Basic, EncodingFormat, Error, Result, Signature, Type};
......@@ -38,6 +39,8 @@ use crate::{Basic, EncodingFormat, Error, Result, Signature, Type};
#[derive(PartialEq, Eq, Hash, Clone)]
pub struct ObjectPath<'a>(Cow<'a, [u8]>);
assert_impl_all!(ObjectPath<'_>: Send, Sync, Unpin);
impl<'a> ObjectPath<'a> {
/// The object path as a string.
pub fn as_str(&self) -> &str {
......@@ -283,6 +286,8 @@ fn ensure_correct_object_path_str(path: &[u8]) -> Result<()> {
#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, serde::Serialize, zvariant_derive::Type)]
pub struct OwnedObjectPath(ObjectPath<'static>);
assert_impl_all!(OwnedObjectPath: Send, Sync, Unpin);
impl OwnedObjectPath {
pub fn into_inner(self) -> ObjectPath<'static> {
self.0
......
use serde::{Deserialize, Deserializer, Serialize};
use static_assertions::assert_impl_all;
use std::{collections::HashMap, convert::TryFrom, hash::BuildHasher};
use crate::{
......@@ -16,6 +17,8 @@ use crate::Maybe;
#[derive(Debug, Clone, PartialEq, Serialize)]
pub struct OwnedValue(Value<'static>);
assert_impl_all!(OwnedValue: Send, Sync, Unpin);
impl OwnedValue {
pub(crate) fn into_inner(self) -> Value<'static> {
self.0
......
use byteorder::WriteBytesExt;
use serde::{ser, Serialize};
use static_assertions::assert_impl_all;
use std::{
io::{Seek, Write},
marker::PhantomData,
......@@ -325,6 +326,8 @@ pub enum Serializer<'ser, 'sig, B, W> {
GVariant(GVSerializer<'ser, 'sig, B, W>),
}
assert_impl_all!(Serializer<'_, '_, i32, i32>: Send, Sync, Unpin);
impl<'ser, 'sig, B, W> Serializer<'ser, 'sig, B, W>
where
B: byteorder::ByteOrder,
......
use serde::ser::{Serialize, SerializeStruct, Serializer};
use static_assertions::assert_impl_all;
use crate::{Signature, Type, Value};
......@@ -17,6 +18,8 @@ use crate::{Signature, Type, Value};
/// [`Value`]: enum.Value.html
pub struct SerializeValue<'a, T: Type + Serialize>(pub &'a T);
assert_impl_all!(SerializeValue<'_, i32>: Send, Sync, Unpin);
impl<'a, T: Type + Serialize> Serialize for SerializeValue<'a, T> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
......
......@@ -7,6 +7,7 @@ use serde::{
de::{Deserialize, Deserializer, Visitor},
ser::{Serialize, Serializer},
};
use static_assertions::assert_impl_all;
use std::{
ops::{Bound, RangeBounds},
sync::Arc,
......@@ -87,6 +88,8 @@ pub struct Signature<'a> {
end: usize,
}
assert_impl_all!(Signature<'_>: Send, Sync, Unpin);
impl<'a> Signature<'a> {
/// The signature as a string.
pub fn as_str(&self) -> &str {
......@@ -375,6 +378,8 @@ fn ensure_correct_signature_str(signature: &[u8]) -> Result<()> {
#[derive(Debug, Clone, PartialEq, serde::Serialize, zvariant_derive::Type)]
pub struct OwnedSignature(Signature<'static>);
assert_impl_all!(OwnedSignature: Send, Sync, Unpin);
impl OwnedSignature {
pub fn into_inner(self) -> Signature<'static> {
self.0
......
......@@ -2,6 +2,7 @@
#![allow(deprecated)]
use serde::{Deserialize, Serialize};
use static_assertions::assert_impl_all;
use std::{borrow::Cow, str};
use crate::{Basic, EncodingFormat, Signature, Type};
......@@ -18,6 +19,8 @@ use crate::{Basic, EncodingFormat, Signature, Type};
#[serde(rename(serialize = "zvariant::Str", deserialize = "zvariant::Str"))]
pub struct Str<'a>(#[serde(borrow)] Cow<'a, str>);
assert_impl_all!(Str<'_>: Send, Sync, Unpin);
impl<'a> Str<'a> {
/// The underlying string.
pub fn as_str(&self) -> &str {
......
use serde::ser::{Serialize, SerializeTupleStruct, Serializer};
use static_assertions::assert_impl_all;
use crate::{OwnedValue, Signature, Type, Value};
......@@ -8,6 +9,8 @@ use crate::{OwnedValue, Signature, Type, Value};
#[derive(Debug, Default, Clone, PartialEq)]
pub struct StructureBuilder<'a>(Vec<Value<'a>>);
assert_impl_all!(StructureBuilder<'_>: Send, Sync, Unpin);
impl<'a> StructureBuilder<'a> {
/// Create a new `StructureBuilder`.
///
......@@ -68,6 +71,8 @@ pub struct Structure<'a> {
signature: Signature<'a>,
}
assert_impl_all!(Structure<'_>: Send, Sync, Unpin);
impl<'a> Structure<'a> {
/// Get a reference to all the fields of `self`.
pub fn fields(&self) -> &[Value<'a>] {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment