#php #serde #var-export

serde_var_export

PHP function var_export() support for Serde

1 unstable release

0.1.0 Jan 28, 2020
0.0.0 Jan 22, 2020

#51 in #php

Unlicense

29KB
786 lines

serde_var_export

Actions Crate API

PHP function var_export() support for Serde.

Installation

With cargo add installed run:

$ cargo add -s serde_var_export

Example

use serde_derive::Serialize;
                                                                                                                                                     
#[derive(Serialize)]
struct Foo {
    names: Vec<String>,
    nums: Vec<i32>,
}
                                                                                                                                                     
fn main() {
    let foo = Foo {
        names: vec!["hello".to_owned(), "world".to_owned()],
        nums: vec![1, 2, 3],
    };
    let s = serde_var_export::to_string(&foo).unwrap();
    println!("{}", s);
}

print result:

array(
  'names' =>
  array(
    0 => 'hello',
    1 => 'world',
  ),
  'nums' =>
  array(
    0 => 1,
    1 => 2,
    2 => 3,
  ),
)

Limitation

Now only support serialization, deserialization will support in future.

License

The Unlicense.

Dependencies

~0.4–1MB
~22K SLoC