nextcloud-client-api 0.1.0

implementation of the socket API for the NextCloud client
Documentation
use core::result::Result as StdResult;

use thiserror::Error as ThisError;

#[derive(Debug)]
#[non_exhaustive]
pub enum ShareStatus {
    /// `Nop` represents some issue, like the file is not in a registered
    /// path or sharing options are disabled in the account.
    Nop,
    /// `NotConnected` indicates, that there is no uplink to a backend.
    /// Therefore no share can be created.
    NotConnected,
    /// `NotSynced` indicates, that the file is not synced yet. So the
    /// backend might not know about it. Therefore no share can be created.
    NotSynced,
    /// `CannotShareRoot` denies the sharing of the root directory of
    /// the account.
    CannotShareRoot,
    /// `Ok` does not confirm the sharing, but that the corresponding
    /// dialog will be opened.
    Ok,
}

#[derive(Debug, ThisError)]
#[non_exhaustive]
pub enum Error {
    #[error("failed to parse status: {0}")]
    ParsingFailed(String),
}

impl TryFrom<&str> for ShareStatus {
    type Error = Error;

    fn try_from(value: &str) -> StdResult<Self, Self::Error> {
        Ok(match value {
            "NOP" => Self::Nop,
            "NOTCONNECTED" => Self::NotConnected,
            "NOTSYNCED" => Self::NotSynced,
            "CANNOTSHAREROOT" => Self::CannotShareRoot,
            "OK" => Self::Ok,
            _ => return Err(Error::ParsingFailed(format!("invalid status: {value}"))),
        })
    }
}