From 54153914d22180777b25a1d4f5089ed2ae2839df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Wed, 13 Jan 2021 23:19:05 +0100 Subject: de-pub links on mumlib channels --- mumlib/src/state.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'mumlib/src/state.rs') diff --git a/mumlib/src/state.rs b/mumlib/src/state.rs index 6fad332..772e822 100644 --- a/mumlib/src/state.rs +++ b/mumlib/src/state.rs @@ -12,14 +12,30 @@ pub struct Server { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Channel { pub description: Option, - pub links: Vec>, //to represent several walks through the tree to find channels its linked to pub max_users: u32, pub name: String, pub children: Vec, pub users: Vec, + + links: Vec>, //to represent several walks through the tree to find channels its linked to } impl Channel { + pub fn new( + name: String, + description: Option, + max_users: u32, + ) -> Self { + Self { + description, + max_users, + name, + children: Vec::new(), + users: Vec::new(), + + links: Vec::new(), + } + } pub fn iter(&self) -> Iter<'_> { Iter { me: Some(&self), -- cgit v1.2.1 From eee62e0892b1247ce321cd30747ab90d58f49732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Wed, 13 Jan 2021 23:19:22 +0100 Subject: document mumlib --- mumlib/src/state.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'mumlib/src/state.rs') diff --git a/mumlib/src/state.rs b/mumlib/src/state.rs index 772e822..182a8fc 100644 --- a/mumlib/src/state.rs +++ b/mumlib/src/state.rs @@ -36,6 +36,9 @@ impl Channel { links: Vec::new(), } } + + /// Create an iterator over this channel and its children in a pre-order + /// traversal. pub fn iter(&self) -> Iter<'_> { Iter { me: Some(&self), @@ -48,6 +51,8 @@ impl Channel { } } + /// Create an iterator over this channel and its childrens connected users + /// in a pre-order traversal. pub fn users_iter(&self) -> UsersIter<'_> { UsersIter { channels: self.children.iter().map(|e| e.users_iter()).collect(), @@ -62,6 +67,7 @@ impl Channel { } } +/// An iterator over channels. Created by [Channel::iter]. pub struct Iter<'a> { me: Option<&'a Channel>, channel: Option, @@ -92,6 +98,7 @@ impl<'a> Iterator for Iter<'a> { } } +/// An iterator over users. Created by [Channel::users_iter]. pub struct UsersIter<'a> { channel: Option, channels: Vec>, -- cgit v1.2.1 From 14ecdfe2365682e37df99569747b96943ec55426 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Tue, 15 Jun 2021 13:41:45 +0200 Subject: doc mumlib state --- mumlib/src/state.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'mumlib/src/state.rs') diff --git a/mumlib/src/state.rs b/mumlib/src/state.rs index 182a8fc..a5262e0 100644 --- a/mumlib/src/state.rs +++ b/mumlib/src/state.rs @@ -1,26 +1,38 @@ use serde::{Deserialize, Serialize}; use std::fmt; +/// The state of the currently connected Mumble server. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Server { + /// State of the currently connected channel. pub channels: Channel, + /// The welcome text we received when we connected. pub welcome_text: Option, + /// Our username. pub username: String, + /// The host (ip:port) of the server. pub host: String, } +/// A representation of a channel in a Mumble server. #[derive(Clone, Debug, Deserialize, Serialize)] pub struct Channel { + /// The description of the channel, if set. pub description: Option, + /// The maximum number of allowed users in this channel. pub max_users: u32, + /// The name of this channel. pub name: String, + /// Any children this channel has. pub children: Vec, + /// This channel's connected users. pub users: Vec, links: Vec>, //to represent several walks through the tree to find channels its linked to } impl Channel { + /// Create a new Channel representation. pub fn new( name: String, description: Option, -- cgit v1.2.1 From c774aadf26b7ecc08a548ed5d781ea3fc5eac1b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Tue, 15 Jun 2021 13:48:24 +0200 Subject: expand on pre order traversal --- mumlib/src/state.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'mumlib/src/state.rs') diff --git a/mumlib/src/state.rs b/mumlib/src/state.rs index a5262e0..72c01a6 100644 --- a/mumlib/src/state.rs +++ b/mumlib/src/state.rs @@ -49,8 +49,10 @@ impl Channel { } } - /// Create an iterator over this channel and its children in a pre-order - /// traversal. + /// Create an iterator over this channel and its children in a [pre-order + /// traversal](https://en.wikipedia.org/wiki/Tree_traversal#Pre-order,_NLR) + /// which ensures that parent channels are returned before any of its + /// children. pub fn iter(&self) -> Iter<'_> { Iter { me: Some(&self), -- cgit v1.2.1