Skip to content

Commit

Permalink
feat: Add plugin struct
Browse files Browse the repository at this point in the history
  • Loading branch information
DashieTM committed Mar 17, 2024
1 parent 5d26982 commit cc87f82
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "re_set-lib"
version = "2.1.0"
version = "2.2.0"
edition = "2021"
description = "Data structure library for ReSet"
repository = "https://github.com/Xetibo/ReSet-Lib"
Expand All @@ -9,4 +9,5 @@ license = "GPL-3.0-only"
[dependencies]
directories-next = "2.0.0"
dbus = "0.9.7"
dbus-crossroads = "0.5.2"
pulse = { version = "2.0", package = "libpulse-binding" }
10 changes: 10 additions & 0 deletions src/utils/plugin.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::collections::HashMap;

use dbus::Path;

use super::variant::Variant;

pub fn plugin_data() -> PluginData {
Expand All @@ -23,3 +25,11 @@ impl PluginData {
self.0.clone()
}
}

#[repr(C)]
pub struct Plugin {
pub path: Path<'static>,
pub interfaces: Vec<dbus_crossroads::IfaceToken<PluginData>>,
pub data: PluginData,
}

42 changes: 21 additions & 21 deletions src/utils/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ impl<T: std::fmt::Debug> Debug for Option<T> {}
impl<K: std::fmt::Debug, V: std::fmt::Debug> Debug for HashMap<K, V> {}

pub trait TVariant: Debug + Any + Send {
fn into_mock_variant(self) -> Variant;
fn into_variant(self) -> Variant;
fn value(&self) -> Box<dyn TVariant>;
}

impl TVariant for bool {
fn into_mock_variant(self) -> Variant {
fn into_variant(self) -> Variant {
Variant::new::<bool>(self)
}
fn value(&self) -> Box<dyn TVariant> {
Box::new(*self)
}
}
impl TVariant for u8 {
fn into_mock_variant(self) -> Variant {
fn into_variant(self) -> Variant {
Variant::new::<u8>(self)
}

Expand All @@ -44,7 +44,7 @@ impl TVariant for u8 {
}
}
impl TVariant for i8 {
fn into_mock_variant(self) -> Variant {
fn into_variant(self) -> Variant {
Variant::new::<i8>(self)
}

Expand All @@ -53,55 +53,55 @@ impl TVariant for i8 {
}
}
impl TVariant for u16 {
fn into_mock_variant(self) -> Variant {
fn into_variant(self) -> Variant {
Variant::new::<u16>(self)
}
fn value(&self) -> Box<dyn TVariant> {
Box::new(*self)
}
}
impl TVariant for i16 {
fn into_mock_variant(self) -> Variant {
fn into_variant(self) -> Variant {
Variant::new::<i16>(self)
}
fn value(&self) -> Box<dyn TVariant> {
Box::new(*self)
}
}
impl TVariant for u32 {
fn into_mock_variant(self) -> Variant {
fn into_variant(self) -> Variant {
Variant::new::<u32>(self)
}
fn value(&self) -> Box<dyn TVariant> {
Box::new(*self)
}
}
impl TVariant for i32 {
fn into_mock_variant(self) -> Variant {
fn into_variant(self) -> Variant {
Variant::new::<i32>(self)
}
fn value(&self) -> Box<dyn TVariant> {
Box::new(*self)
}
}
impl TVariant for u64 {
fn into_mock_variant(self) -> Variant {
fn into_variant(self) -> Variant {
Variant::new::<u64>(self)
}
fn value(&self) -> Box<dyn TVariant> {
Box::new(*self)
}
}
impl TVariant for i64 {
fn into_mock_variant(self) -> Variant {
fn into_variant(self) -> Variant {
Variant::new::<i64>(self)
}
fn value(&self) -> Box<dyn TVariant> {
Box::new(*self)
}
}
impl TVariant for String {
fn into_mock_variant(self) -> Variant {
fn into_variant(self) -> Variant {
Variant::new::<String>(self.clone())
}
fn value(&self) -> Box<dyn TVariant> {
Expand All @@ -112,7 +112,7 @@ impl<T: Debug + Send + 'static> TVariant for Option<T>
where
T: Clone,
{
fn into_mock_variant(self) -> Variant {
fn into_variant(self) -> Variant {
Variant::new(self)
}
fn value(&self) -> Box<dyn TVariant> {
Expand All @@ -123,7 +123,7 @@ impl<T: Debug + Send + 'static> TVariant for Vec<T>
where
T: Clone,
{
fn into_mock_variant(self) -> Variant {
fn into_variant(self) -> Variant {
Variant::new(self)
}
fn value(&self) -> Box<dyn TVariant> {
Expand All @@ -135,7 +135,7 @@ where
K: Clone,
V: Clone,
{
fn into_mock_variant(self) -> Variant {
fn into_variant(self) -> Variant {
Variant::new(self)
}
fn value(&self) -> Box<dyn TVariant> {
Expand Down Expand Up @@ -197,7 +197,7 @@ pub struct ConversionError(pub &'static str);
pub struct Empty {}

impl TVariant for Empty {
fn into_mock_variant(self) -> Variant {
fn into_variant(self) -> Variant {
Variant::new::<Empty>(self)
}

Expand All @@ -208,21 +208,21 @@ impl TVariant for Empty {

#[test]
fn test_i32() {
let mock = 5.into_mock_variant();
let mock = 5.into_variant();
assert_eq!(mock.kind, TypeId::of::<i32>());
assert_eq!(mock.to_value::<i32>().unwrap(), 5);
}

#[test]
fn test_option() {
let mock = Some(10).into_mock_variant();
let mock = Some(10).into_variant();
assert_eq!(mock.kind, TypeId::of::<Option<i32>>());
assert_eq!(mock.to_value::<Option<i32>>().unwrap(), Some(10));
}

#[test]
fn test_vec() {
let mock = vec![3, 2, 4, 5, 10].into_mock_variant();
let mock = vec![3, 2, 4, 5, 10].into_variant();
assert_eq!(mock.kind, TypeId::of::<Vec<i32>>());
assert_eq!(
mock.to_value_cloned::<Vec<i32>>().unwrap().clone(),
Expand All @@ -234,7 +234,7 @@ fn test_vec() {
fn test_hashmap() {
let mut map = HashMap::new();
map.insert("Something".to_string(), 20);
let mock = map.into_mock_variant();
let mock = map.into_variant();

let mut testmap = HashMap::new();
testmap.insert("Something".to_string(), 20);
Expand All @@ -250,7 +250,7 @@ fn test_hashmap() {

#[test]
fn test_conversion_fail() {
let mock = "hello".to_string().into_mock_variant();
let mock = "hello".to_string().into_variant();
assert_eq!(mock.kind, TypeId::of::<String>());
assert!(mock.to_value_cloned::<i32>().is_err());
}
Expand All @@ -259,7 +259,7 @@ fn test_conversion_fail() {
fn test_variant_clone() {
let mut map = HashMap::new();
map.insert("Something".to_string(), 20);
let mock = map.into_mock_variant();
let mock = map.into_variant();
let new_mock = mock.clone();

let mut testmap = HashMap::new();
Expand Down

0 comments on commit cc87f82

Please sign in to comment.