Make tag API functions non-nil

This commit is contained in:
Ottatop 2023-10-18 20:16:26 -05:00
parent 17ca00f6be
commit 474da43280
3 changed files with 15 additions and 11 deletions

View file

@ -62,7 +62,7 @@
---@field ConnectForAllOutputs { output_name: string }?
---@alias WindowId integer | "None"
---@alias TagId integer
---@alias TagId integer | "None"
---@alias RequestId integer
---@alias OutputName string

View file

@ -54,7 +54,7 @@ local tag = {}
---This can be retrieved through the various `get` functions in the `Tag` module.
---@classmod
---@class TagHandle
---@field private _id integer The internal id of this tag.
---@field private _id TagId The internal id of this tag.
local tag_handle = {}
---Create a tag from an id.
@ -74,7 +74,7 @@ end
---Get this tag's internal id.
---***You probably won't need to use this.***
---@return integer
---@return TagId
function tag_handle:id()
return self._id
end
@ -275,7 +275,7 @@ end
---end
---```
---@param params TagConstructor
---@return TagHandle|nil
---@return TagHandle
---
---@see Tag.get_on_output — Get all tags on an output
---@see Tag.get_by_name — Get all tags with some name
@ -290,7 +290,7 @@ function tag.get(params)
if type(params) == "string" then
local op = require("output").get_focused()
if op == nil then
return nil
return create_tag("None")
end
local tags = tag.get_by_name(params)
@ -300,7 +300,7 @@ function tag.get(params)
end
end
return nil
return create_tag("None")
end
-- TagTable was passed in
@ -311,13 +311,13 @@ function tag.get(params)
if op == nil then
local o = require("output").get_focused()
if o == nil then
return nil
return create_tag("None")
end
op = o
elseif type(op) == "string" then
local o = require("output").get_by_name(op)
if o == nil then
return nil
return create_tag("None")
end
op = o
end
@ -329,7 +329,7 @@ function tag.get(params)
end
end
return nil
return create_tag("None")
end
---Get all tags on the specified output.

View file

@ -17,11 +17,15 @@ use crate::{
static TAG_ID_COUNTER: AtomicU32 = AtomicU32::new(0);
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy, serde::Serialize, serde::Deserialize)]
pub struct TagId(u32);
pub enum TagId {
None,
#[serde(untagged)]
Some(u32),
}
impl TagId {
fn next() -> Self {
Self(TAG_ID_COUNTER.fetch_add(1, Ordering::Relaxed))
Self::Some(TAG_ID_COUNTER.fetch_add(1, Ordering::Relaxed))
}
pub fn tag(&self, state: &State) -> Option<Tag> {