aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/json/json_file.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-05 05:10:50 +0900
committernsfisis <nsfisis@gmail.com>2026-06-05 05:10:50 +0900
commit0bd0c361297903888c1f53af67d547ef2858882f (patch)
treed8dcd1e116569583252c530cf83b8ac41b1f1e86 /crates/shirabe/src/json/json_file.rs
parentd0edb5b7ac3456f99c2f2576e8992cc12d60574a (diff)
downloadphp-shirabe-0bd0c361297903888c1f53af67d547ef2858882f.tar.gz
php-shirabe-0bd0c361297903888c1f53af67d547ef2858882f.tar.zst
php-shirabe-0bd0c361297903888c1f53af67d547ef2858882f.zip
refactor(json): make json encode helpers accept serde::Serialize
Change json_encode/json_encode_ex and JsonFile::encode/encode_with_options to take a generic serde::Serialize value instead of &PhpMixed, implement Serialize for PhpMixed/ArrayObject, and drop the PhpMixed::String wrapping at JsonManipulator call sites in favor of passing raw values. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/json/json_file.rs')
-rw-r--r--crates/shirabe/src/json/json_file.rs7
1 files changed, 5 insertions, 2 deletions
diff --git a/crates/shirabe/src/json/json_file.rs b/crates/shirabe/src/json/json_file.rs
index 06f3946..0aa44fc 100644
--- a/crates/shirabe/src/json/json_file.rs
+++ b/crates/shirabe/src/json/json_file.rs
@@ -426,11 +426,14 @@ impl JsonFile {
Ok(true)
}
- pub fn encode(data: &PhpMixed) -> String {
+ pub fn encode<T: serde::Serialize + ?Sized>(data: &T) -> String {
Self::encode_with_options(data, JsonEncodeOptions::default())
}
- pub fn encode_with_options(data: &PhpMixed, options: JsonEncodeOptions) -> String {
+ pub fn encode_with_options<T: serde::Serialize + ?Sized>(
+ data: &T,
+ options: JsonEncodeOptions,
+ ) -> String {
let json = json_encode_ex(data, options.to_flags());
let json = match json {