Skip to content

Commit

Permalink
Fix some formatting so that syntax highlighting is happy
Browse files Browse the repository at this point in the history
  • Loading branch information
TTWNO committed Jun 27, 2024
1 parent b1167aa commit e2ec47d
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions atspi-common/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde::{
ser::{SerializeSeq, Serializer},
Deserialize, Serialize,
};
use std::fmt;
use std::{convert::Infallible, fmt, str::FromStr};
use zvariant::{Signature, Type};

/// Used by various interfaces indicating every possible state
Expand Down Expand Up @@ -279,6 +279,13 @@ impl From<String> for State {
}
}

impl FromStr for State {
type Err = Infallible;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(s.into())
}
}

impl From<&str> for State {
fn from(string: &str) -> State {
match string {
Expand Down Expand Up @@ -338,20 +345,20 @@ pub struct StateSet(BitFlags<State>);
impl StateSet {
/// Create a new `StateSet`.
///
///## Example
///```Rust
/// let states = State::Focusable | State::Sensitive | State::Active;
/// let set = StateSet::new(states);
/// ## Example
/// ```rust
/// let states = State::Focusable | State::Sensitive | State::Active;
/// let set = StateSet::new(states);
///
/// assert!(set.contains(State::Active));
/// assert!(!set.contains(State::Busy));
/// assert!(set.contains(State::Active));
/// assert!(!set.contains(State::Busy));
/// ```
pub fn new<B: Into<BitFlags<State>>>(value: B) -> Self {
Self(value.into())
}

/// Returns the `StateSet` that corresponds to the provided `u64`s bit pattern.
///# Errors
/// # Errors
/// When the argument encodes an undefined [`State`].
pub fn from_bits(bits: u64) -> Result<StateSet, FromBitsError<State>> {
Ok(StateSet(BitFlags::from_bits(bits)?))
Expand Down

0 comments on commit e2ec47d

Please sign in to comment.