mirror of
https://github.com/Blah-IM/blahrs.git
synced 2025-05-01 08:41:09 +00:00
Derive Clone, PartialEq, Eq for data types
This commit is contained in:
parent
51e2c8418b
commit
e98c9f8b3c
1 changed files with 14 additions and 14 deletions
28
src/types.rs
28
src/types.rs
|
@ -24,7 +24,7 @@ impl fmt::Display for Id {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
pub struct WithItemId<T> {
|
pub struct WithItemId<T> {
|
||||||
pub cid: Id,
|
pub cid: Id,
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
|
@ -43,7 +43,7 @@ impl fmt::Display for UserKey {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
#[serde(deny_unknown_fields)]
|
#[serde(deny_unknown_fields)]
|
||||||
pub struct WithSig<T> {
|
pub struct WithSig<T> {
|
||||||
#[serde(with = "hex::serde")]
|
#[serde(with = "hex::serde")]
|
||||||
|
@ -51,7 +51,7 @@ pub struct WithSig<T> {
|
||||||
pub signee: Signee<T>,
|
pub signee: Signee<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
#[serde(deny_unknown_fields)]
|
#[serde(deny_unknown_fields)]
|
||||||
pub struct Signee<T> {
|
pub struct Signee<T> {
|
||||||
pub nonce: u32,
|
pub nonce: u32,
|
||||||
|
@ -98,7 +98,7 @@ impl<T: Serialize> WithSig<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: `deny_unknown_fields` breaks this.
|
// FIXME: `deny_unknown_fields` breaks this.
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
#[serde(tag = "typ", rename = "chat")]
|
#[serde(tag = "typ", rename = "chat")]
|
||||||
pub struct ChatPayload {
|
pub struct ChatPayload {
|
||||||
pub rich_text: RichText,
|
pub rich_text: RichText,
|
||||||
|
@ -106,11 +106,11 @@ pub struct ChatPayload {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ref: <https://github.com/Blah-IM/Weblah/blob/a3fa0f265af54c846f8d65f42aa4409c8dba9dd9/src/lib/richText.ts>
|
/// Ref: <https://github.com/Blah-IM/Weblah/blob/a3fa0f265af54c846f8d65f42aa4409c8dba9dd9/src/lib/richText.ts>
|
||||||
#[derive(Debug, Default, PartialEq, Eq, Serialize)]
|
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize)]
|
||||||
#[serde(transparent)]
|
#[serde(transparent)]
|
||||||
pub struct RichText(pub Vec<RichTextPiece>);
|
pub struct RichText(pub Vec<RichTextPiece>);
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct RichTextPiece {
|
pub struct RichTextPiece {
|
||||||
pub attrs: TextAttrs,
|
pub attrs: TextAttrs,
|
||||||
pub text: String,
|
pub text: String,
|
||||||
|
@ -130,7 +130,7 @@ impl Serialize for RichTextPiece {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The protocol representation of `RichTextPiece`.
|
/// The protocol representation of `RichTextPiece`.
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
enum RichTextPieceRaw {
|
enum RichTextPieceRaw {
|
||||||
Text(String),
|
Text(String),
|
||||||
|
@ -295,7 +295,7 @@ impl RichText {
|
||||||
|
|
||||||
pub type ChatItem = WithSig<ChatPayload>;
|
pub type ChatItem = WithSig<ChatPayload>;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
#[serde(tag = "typ", rename = "create_room")]
|
#[serde(tag = "typ", rename = "create_room")]
|
||||||
pub struct CreateRoomPayload {
|
pub struct CreateRoomPayload {
|
||||||
pub attrs: RoomAttrs,
|
pub attrs: RoomAttrs,
|
||||||
|
@ -308,7 +308,7 @@ pub struct CreateRoomPayload {
|
||||||
/// A collection of room members, with these invariants:
|
/// A collection of room members, with these invariants:
|
||||||
/// 1. Sorted by userkeys.
|
/// 1. Sorted by userkeys.
|
||||||
/// 2. No duplicated users.
|
/// 2. No duplicated users.
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
||||||
#[serde(try_from = "Vec<RoomMember>")]
|
#[serde(try_from = "Vec<RoomMember>")]
|
||||||
pub struct RoomMemberList(pub Vec<RoomMember>);
|
pub struct RoomMemberList(pub Vec<RoomMember>);
|
||||||
|
|
||||||
|
@ -333,7 +333,7 @@ impl TryFrom<Vec<RoomMember>> for RoomMemberList {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
pub struct RoomMember {
|
pub struct RoomMember {
|
||||||
pub permission: MemberPermission,
|
pub permission: MemberPermission,
|
||||||
pub user: UserKey,
|
pub user: UserKey,
|
||||||
|
@ -342,11 +342,11 @@ pub struct RoomMember {
|
||||||
/// Proof of room membership for read-access.
|
/// Proof of room membership for read-access.
|
||||||
///
|
///
|
||||||
/// TODO: Should we use JWT here instead?
|
/// TODO: Should we use JWT here instead?
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
#[serde(tag = "typ", rename = "auth")]
|
#[serde(tag = "typ", rename = "auth")]
|
||||||
pub struct AuthPayload {}
|
pub struct AuthPayload {}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
#[serde(tag = "typ", rename_all = "snake_case")]
|
#[serde(tag = "typ", rename_all = "snake_case")]
|
||||||
pub struct RoomAdminPayload {
|
pub struct RoomAdminPayload {
|
||||||
pub room: Id,
|
pub room: Id,
|
||||||
|
@ -354,7 +354,7 @@ pub struct RoomAdminPayload {
|
||||||
pub op: RoomAdminOp,
|
pub op: RoomAdminOp,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
#[serde(tag = "typ", rename_all = "snake_case")]
|
#[serde(tag = "typ", rename_all = "snake_case")]
|
||||||
pub enum RoomAdminOp {
|
pub enum RoomAdminOp {
|
||||||
AddMember {
|
AddMember {
|
||||||
|
@ -500,7 +500,7 @@ mod tests {
|
||||||
expect.assert_eq(&json);
|
expect.assert_eq(&json);
|
||||||
|
|
||||||
let roundtrip_item = serde_json::from_str::<WithSig<ChatPayload>>(&json).unwrap();
|
let roundtrip_item = serde_json::from_str::<WithSig<ChatPayload>>(&json).unwrap();
|
||||||
// assert_eq!(roundtrip_item, item);
|
assert_eq!(roundtrip_item, item);
|
||||||
roundtrip_item.verify().unwrap();
|
roundtrip_item.verify().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue