use super::{DecodedGuestString, GuestDecodeError, GuestDecodeField, GuestDecodeLimits};
use crate::plugin::{WorkspacePath, WorkspacePathRef};
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct DecodedWorkspacePath {
value: WorkspacePath,
}
impl DecodedWorkspacePath {
pub fn from_bytes(
field: GuestDecodeField,
bytes: &[u8],
limits: GuestDecodeLimits,
) -> Result<Self, GuestDecodeError> {
let value = WorkspacePath::try_new(
DecodedGuestString::from_bytes(field, bytes, limits)?.into_string(),
)
.map_err(|source| GuestDecodeError::InvalidWorkspacePath { field, source })?;
Ok(Self { value })
}
#[must_use]
pub const fn as_ref(&self) -> WorkspacePathRef<'_> {
self.value.as_ref()
}
#[must_use]
pub fn as_str(&self) -> &str {
self.value.as_str()
}
}