airlab_lib/ctx/
mod.rs

1mod error;
2
3pub use self::error::{Error, Result};
4
5#[derive(Clone, Debug)]
6pub struct Ctx {
7    user_id: i32,
8}
9
10impl Ctx {
11    #[must_use]
12    pub const fn root_ctx() -> Self {
13        Self { user_id: 0 }
14    }
15
16    pub const fn new(user_id: i32) -> Result<Self> {
17        if user_id == 0 {
18            Err(Error::CtxCannotNewRootCtx)
19        } else {
20            Ok(Self { user_id })
21        }
22    }
23}
24
25impl Ctx {
26    #[must_use]
27    pub const fn user_id(&self) -> i32 {
28        self.user_id
29    }
30}