Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/Users #38

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions Modules/Task/src/Manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
sync::{OnceLock, RwLock},
time::Duration,
};
use Users::{Root_user_identifier, User_identifier_type};
use Users::User_identifier_type;

/// Internal representation of a task.
struct Task_internal_type {
Expand Down Expand Up @@ -68,7 +68,7 @@ impl Manager_type {
let Task_internal = Task_internal_type {
Main_thread: Thread_wrapper_type::Get_current(),
Parent: Task_identifier,
Owner: Root_user_identifier,
Owner: User_identifier_type::Root,
Environment_variables: vec![],
};

Expand Down Expand Up @@ -102,7 +102,7 @@ impl Manager_type {
let Task_internal = Task_internal_type {
Main_thread: Thread_wrapper_type::Get_current(),
Parent: Self::Root_task_identifier,
Owner: Root_user_identifier,
Owner: User_identifier_type::Root,
Environment_variables: vec![],
};

Expand Down Expand Up @@ -558,7 +558,7 @@ mod Tests {
}

fn Test_get_owner(Manager: &Manager_type) {
let User_identifier = 123; // Assuming User_identifier_type is i32 for example
let User_identifier = User_identifier_type::New(123); // Assuming User_identifier_type is i32 for example

let Task = Manager.Get_current_task_identifier().unwrap();

Expand Down Expand Up @@ -590,7 +590,7 @@ mod Tests {
}

fn Test_task_owner_inheritance(Manager: &Manager_type) {
let User_identifier = 123; // Assuming User_identifier_type is i32 for example
let User_identifier = User_identifier_type::New(123); // Assuming User_identifier_type is i32 for example
let Task = Manager.Get_current_task_identifier().unwrap();

let _ = Manager
Expand All @@ -611,12 +611,14 @@ mod Tests {
})
.unwrap();

let User_identifier = User_identifier_type::New(6969); // Assuming User_identifier_type is i32 for example

// - Overwrite owner
let _ = Get_instance()
.New_task(Task, Some(6969), "Task 3", None, move || {
.New_task(Task, Some(User_identifier), "Task 3", None, move || {
let Task = Get_instance().Get_current_task_identifier().unwrap();

assert_eq!(Get_instance().Get_owner(Task).unwrap(), 6969);
assert_eq!(Get_instance().Get_owner(Task).unwrap(), User_identifier);
assert_eq!(Get_instance().Get_task_name(Task).unwrap(), "Task 3");
})
.unwrap();
Expand Down
89 changes: 89 additions & 0 deletions Modules/Users/src/Identifiers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
use std::ops::{Add, AddAssign};

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Ord, PartialOrd)]
#[repr(transparent)]
pub struct User_identifier_type(u16);

impl User_identifier_type {
pub const Root: Self = Self::New(0);

pub const Minimum: Self = Self::New(1);
pub const Maximum: Self = Self::New(u16::MAX);

pub const fn New(Identifier: u16) -> Self {
Self(Identifier)
}

pub const fn Into_inner(self) -> u16 {
self.0
}
}

impl AddAssign<u16> for User_identifier_type {
fn add_assign(&mut self, Other: u16) {
self.0 += Other;
}
}

impl Add<u16> for User_identifier_type {
type Output = Self;

fn add(self, Other: u16) -> Self {
Self::New(self.0 + Other)
}
}

impl From<u16> for User_identifier_type {
fn from(Value: u16) -> Self {
User_identifier_type::New(Value)
}
}
impl From<User_identifier_type> for u16 {
fn from(Value: User_identifier_type) -> Self {
Value.Into_inner()
}
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Ord, PartialOrd)]
#[repr(transparent)]
pub struct Group_identifier_type(u16);

impl Group_identifier_type {
pub const Root: Self = Self::New(0);

pub const Minimum: Self = Self::New(1);
pub const Maximum: Self = Self::New(u16::MAX);

pub const fn New(Identifier: u16) -> Self {
Self(Identifier)
}

pub const fn Into_inner(self) -> u16 {
self.0
}
}

impl From<u16> for Group_identifier_type {
fn from(Value: u16) -> Self {
Group_identifier_type::New(Value)
}
}
impl From<Group_identifier_type> for u16 {
fn from(Value: Group_identifier_type) -> Self {
Value.Into_inner()
}
}

impl AddAssign<u16> for Group_identifier_type {
fn add_assign(&mut self, Other: u16) {
self.0 += Other;
}
}

impl Add<u16> for Group_identifier_type {
type Output = Self;

fn add(self, Other: u16) -> Self {
Self::New(self.0 + Other)
}
}
Loading
Loading