use serde::{Deserialize, Serialize};
use crate::{PeerId, Project};
/// TODO: docs
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Session {
peers: Vec<PeerId>,
project: Project,
}
impl Session {
/// Creates a new `Session`.
#[inline(always)]
pub fn new(project: Project, peers: Vec<PeerId>) -> Self {
Self { project, peers }
}
/// Returns an iterator over the [`PeerId`]s of all the peers in the
/// session.
///
/// Note that a peer being connected to the session doesn't necessarily
/// mean that their cursor is somewhere in the project tree.
#[inline(always)]
pub fn peers(&self) -> impl ExactSizeIterator<Item = PeerId> + '_ {
self.peers.iter().copied()
}
/// Returns a reference to the [`Project`] being shared in this `Session`.
#[inline(always)]
pub fn project(&self) -> &Project {
&self.project
}
}