mirror of
https://github.com/sxyazi/yazi.git
synced 2026-05-13 08:16:40 +00:00
Some checks are pending
Cachix / Publish Flake (push) Waiting to run
Cachix / Publish Flake-1 (push) Waiting to run
Check / clippy (push) Waiting to run
Check / rustfmt (push) Waiting to run
Check / stylua (push) Waiting to run
Draft / build-unix (gcc-aarch64-linux-gnu, ubuntu-latest, aarch64-unknown-linux-gnu) (push) Waiting to run
Draft / build-unix (gcc-i686-linux-gnu, ubuntu-latest, i686-unknown-linux-gnu) (push) Waiting to run
Draft / build-unix (gcc-riscv64-linux-gnu, ubuntu-latest, riscv64gc-unknown-linux-gnu) (push) Waiting to run
Draft / build-unix (gcc-sparc64-linux-gnu, ubuntu-latest, sparc64-unknown-linux-gnu) (push) Waiting to run
Draft / build-unix (macos-latest, aarch64-apple-darwin) (push) Waiting to run
Draft / build-unix (macos-latest, x86_64-apple-darwin) (push) Waiting to run
Draft / build-unix (ubuntu-latest, x86_64-unknown-linux-gnu) (push) Waiting to run
Draft / build-windows (windows-latest, aarch64-pc-windows-msvc) (push) Waiting to run
Draft / build-windows (windows-latest, x86_64-pc-windows-msvc) (push) Waiting to run
Draft / build-musl (aarch64-unknown-linux-musl) (push) Waiting to run
Draft / build-musl (x86_64-unknown-linux-musl) (push) Waiting to run
Draft / build-snap (amd64, ubuntu-latest) (push) Waiting to run
Draft / build-snap (arm64, ubuntu-24.04-arm) (push) Waiting to run
Draft / snap (push) Blocked by required conditions
Draft / draft (push) Blocked by required conditions
Draft / nightly (push) Blocked by required conditions
Test / test (macos-latest) (push) Waiting to run
Test / test (ubuntu-latest) (push) Waiting to run
Test / test (windows-latest) (push) Waiting to run
60 lines
1.5 KiB
Rust
60 lines
1.5 KiB
Rust
use std::{borrow::Borrow, ffi::{OsStr, OsString}, fmt::{Display, Formatter}, ops::Deref};
|
|
|
|
use serde::{Deserialize, Deserializer, Serialize};
|
|
|
|
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
|
|
#[serde(transparent)]
|
|
pub struct NonEmptyString(String);
|
|
|
|
impl NonEmptyString {
|
|
#[inline]
|
|
pub fn new(value: String) -> Option<Self> { Some(Self(value)).filter(|s| !s.is_empty()) }
|
|
}
|
|
|
|
impl Deref for NonEmptyString {
|
|
type Target = str;
|
|
|
|
#[inline]
|
|
fn deref(&self) -> &Self::Target { &self.0 }
|
|
}
|
|
|
|
impl Borrow<str> for NonEmptyString {
|
|
#[inline]
|
|
fn borrow(&self) -> &str { &self.0 }
|
|
}
|
|
|
|
impl Borrow<String> for NonEmptyString {
|
|
#[inline]
|
|
fn borrow(&self) -> &String { &self.0 }
|
|
}
|
|
|
|
impl AsRef<str> for NonEmptyString {
|
|
#[inline]
|
|
fn as_ref(&self) -> &str { &self.0 }
|
|
}
|
|
|
|
impl AsRef<OsStr> for NonEmptyString {
|
|
#[inline]
|
|
fn as_ref(&self) -> &OsStr { self.0.as_ref() }
|
|
}
|
|
|
|
impl Display for NonEmptyString {
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { Display::fmt(&self.0, f) }
|
|
}
|
|
|
|
impl From<NonEmptyString> for String {
|
|
#[inline]
|
|
fn from(value: NonEmptyString) -> Self { value.0 }
|
|
}
|
|
|
|
impl From<NonEmptyString> for OsString {
|
|
#[inline]
|
|
fn from(value: NonEmptyString) -> Self { value.0.into() }
|
|
}
|
|
|
|
impl<'de> Deserialize<'de> for NonEmptyString {
|
|
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
|
|
let value = String::deserialize(deserializer)?;
|
|
Self::new(value).ok_or_else(|| serde::de::Error::custom("must be a non-empty string"))
|
|
}
|
|
}
|