Clarify constructor failures and borrowed API contracts
This commit is contained in:
1 parent
23e280a6b4
commit
a7fcd69897
55 files changed
+332
-102
No files matched your search
@@ -4,6 +4,7 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
pub const VERSION: u32 = 1;
|
||||
|
||||
#[must_use]
|
||||
pub fn now_ms() -> u64 {
|
||||
let mut time = libc::timespec {
|
||||
tv_sec: 0,
|
||||
|
||||
@@ -63,6 +63,7 @@ impl Event {
|
||||
}
|
||||
|
||||
impl Snapshot {
|
||||
#[must_use]
|
||||
pub fn changes_since(&self, previous: &Self) -> Vec<Change> {
|
||||
let mut changes = Vec::new();
|
||||
if self.outputs != previous.outputs {
|
||||
|
||||
@@ -36,6 +36,7 @@ pub struct ResponseError {
|
||||
}
|
||||
|
||||
impl Response {
|
||||
#[must_use]
|
||||
pub fn success(id: u64, result: Value) -> Self {
|
||||
Self {
|
||||
version: VERSION,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[must_use]
|
||||
pub fn now_us() -> u64 {
|
||||
let mut time = libc::timespec {
|
||||
tv_sec: 0,
|
||||
@@ -79,6 +80,7 @@ impl Default for Player {
|
||||
}
|
||||
|
||||
impl Player {
|
||||
#[must_use]
|
||||
pub fn label(&self) -> &str {
|
||||
if self.title.is_empty() {
|
||||
&self.identity
|
||||
@@ -87,6 +89,7 @@ impl Player {
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn can_toggle(&self) -> bool {
|
||||
self.can_control
|
||||
&& if self.status == Playback::Playing {
|
||||
@@ -96,6 +99,7 @@ impl Player {
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn position_at(&self, now_us: u64) -> Option<u64> {
|
||||
let mut position = self.position_us? as f64;
|
||||
if self.status == Playback::Playing && self.rate.is_finite() {
|
||||
|
||||
@@ -17,6 +17,7 @@ pub enum State {
|
||||
}
|
||||
|
||||
impl State {
|
||||
#[must_use]
|
||||
pub fn is_inactive(self) -> bool {
|
||||
matches!(self, Self::Disabled | Self::Idle | Self::Stopped)
|
||||
}
|
||||
@@ -51,6 +52,7 @@ impl Status {
|
||||
serde_json::from_value(value)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn to_value(&self) -> Value {
|
||||
match serde_json::to_value(self) {
|
||||
Ok(value) => value,
|
||||
|
||||
Reference in new issue
Block a user