From c839244d8d09f3036ebfee8eef7eb6b147e593ab Mon Sep 17 00:00:00 2001 From: nsfisis Date: Tue, 19 May 2026 00:10:22 +0900 Subject: fix(compile): fix various compile errors Co-Authored-By: Claude Sonnet 4.6 --- crates/shirabe-php-shim/src/lib.rs | 91 +++++++++++++++++++++++++++++++++++++- 1 file changed, 90 insertions(+), 1 deletion(-) (limited to 'crates/shirabe-php-shim') diff --git a/crates/shirabe-php-shim/src/lib.rs b/crates/shirabe-php-shim/src/lib.rs index a8793cf..e6fbf05 100644 --- a/crates/shirabe-php-shim/src/lib.rs +++ b/crates/shirabe-php-shim/src/lib.rs @@ -9,6 +9,7 @@ pub enum PhpMixed { String(String), List(Vec>), Array(IndexMap>), + Object(ArrayObject), } impl PhpMixed { @@ -57,6 +58,94 @@ impl PhpMixed { pub fn is_null(&self) -> bool { matches!(self, PhpMixed::Null) } + + pub fn as_string_opt(&self) -> Option<&str> { + self.as_string() + } + + pub fn get(&self, key: &str) -> Option<&PhpMixed> { + self.as_array().and_then(|m| m.get(key).map(|v| v.as_ref())) + } + + /// Treats PhpMixed::Null as None, everything else as Some. + pub fn as_opt(&self) -> Option<&PhpMixed> { + if self.is_null() { None } else { Some(self) } + } + + pub fn unwrap_or(self, default: PhpMixed) -> PhpMixed { + if self.is_null() { default } else { self } + } +} + +impl From for PhpMixed { + fn from(_value: bool) -> Self { + todo!() + } +} + +impl From for PhpMixed { + fn from(_value: i64) -> Self { + todo!() + } +} + +impl From for PhpMixed { + fn from(_value: f64) -> Self { + todo!() + } +} + +impl From for PhpMixed { + fn from(_value: String) -> Self { + todo!() + } +} + +impl From<&str> for PhpMixed { + fn from(value: &str) -> Self { + PhpMixed::String(value.to_string()) + } +} + +impl From> for PhpMixed +where + T: Into, +{ + fn from(value: IndexMap) -> Self { + PhpMixed::Array( + value + .into_iter() + .map(|(k, v)| (k, Box::new(v.into()))) + .collect(), + ) + } +} + +impl From> for PhpMixed +where + T: Into, +{ + fn from(value: Vec) -> Self { + PhpMixed::List(value.into_iter().map(|v| Box::new(v.into())).collect()) + } +} + +impl From> for PhpMixed +where + T: Into, +{ + fn from(value: Option) -> Self { + match value { + Some(v) => v.into(), + None => PhpMixed::Null, + } + } +} + +impl std::fmt::Display for PhpMixed { + fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + todo!() + } } #[derive(Debug)] @@ -2038,7 +2127,7 @@ pub const PHP_WINDOWS_VERSION_BUILD: i64 = 0; pub const DATE_RFC3339: &str = "Y-m-d\\TH:i:sP"; pub const PREG_BACKTRACK_LIMIT_ERROR: i64 = 2; -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct ArrayObject { data: IndexMap>, } -- cgit v1.3.1