2023-06-30 21:34:07 -05:00
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2023-07-09 17:48:46 -05:00
|
|
|
use std::{
|
|
|
|
hash::Hash,
|
|
|
|
sync::atomic::{AtomicU32, Ordering},
|
|
|
|
};
|
|
|
|
|
|
|
|
static TAG_ID_COUNTER: AtomicU32 = AtomicU32::new(0);
|
2023-06-30 21:34:07 -05:00
|
|
|
|
2023-07-01 19:06:37 -05:00
|
|
|
#[derive(Debug, Hash, PartialEq, Eq, Clone, serde::Serialize, serde::Deserialize)]
|
2023-07-09 17:48:46 -05:00
|
|
|
pub struct TagId(u32);
|
|
|
|
|
|
|
|
impl TagId {
|
|
|
|
fn next() -> Self {
|
|
|
|
Self(TAG_ID_COUNTER.fetch_add(1, Ordering::Relaxed))
|
|
|
|
}
|
|
|
|
}
|
2023-06-30 21:34:07 -05:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Tag {
|
2023-07-09 17:48:46 -05:00
|
|
|
/// The internal id of this tag.
|
2023-06-30 21:34:07 -05:00
|
|
|
pub id: TagId,
|
2023-07-09 17:48:46 -05:00
|
|
|
/// The name of this tag.
|
|
|
|
pub name: String,
|
|
|
|
/// Whether this tag is active or not.
|
|
|
|
pub active: bool,
|
2023-06-30 21:34:07 -05:00
|
|
|
// TODO: layout
|
|
|
|
}
|
|
|
|
|
2023-07-09 17:48:46 -05:00
|
|
|
impl Tag {
|
2023-07-11 11:59:38 -05:00
|
|
|
pub fn new(name: String) -> Self {
|
2023-07-09 17:48:46 -05:00
|
|
|
Self {
|
|
|
|
id: TagId::next(),
|
|
|
|
name,
|
|
|
|
active: false,
|
|
|
|
}
|
2023-06-30 21:34:07 -05:00
|
|
|
}
|
|
|
|
}
|