speedyspec-php-serialize 0.3.1

PHP's serialize format in Rust: serialize, unserialize, maybe_serialize, and conversions to hook values.
Documentation
  • Coverage
  • 66.67%
    34 out of 51 items documented1 out of 15 items with examples
  • Size
  • Source code size: 63.1 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 583.2 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 6s Average build duration of successful builds.
  • all releases: 5s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • SpeedySpec/speedyspec-platform
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • jacobsantos

speedyspec-php-serialize

crates.io docs.rs MIT

PHP's serialize format in Rust: serialize, unserialize, maybe_serialize, and conversions to hook values.

Part of the SpeedySpec platform. Role: platform. Seam: container.

What it gives you

  • serialize and unserialize: PHP's format, byte for byte, over PhpValue and PhpKey.
  • maybe_serialize, maybe_unserialize and is_serialized: WordPress's helpers.
  • to_hook_value and from_hook_value: conversions to the Hook API's Value.

Install

cargo add speedyspec-php-serialize

Requirements

Rust 1.99.

Example

Serialize an array, check it, and read it back.

use speedyspec_php_serialize::{PhpKey, PhpValue, is_serialized, serialize, unserialize};

let value = PhpValue::Array(vec![(PhpKey::Str(b"a".to_vec()), PhpValue::Int(1))]);
let bytes = serialize(&value);
assert_eq!(bytes, b"a:1:{s:1:\"a\";i:1;}".to_vec());
assert!(is_serialized(&bytes, true));
assert_eq!(unserialize(&bytes).unwrap(), value);

Where it fits

Options, metadata and theme.json values are stored serialized, so the contracts for those seams (speedyspec-wp-meta-contracts, speedyspec-wp-posts-contracts, speedyspec-wp-theme-json-contracts) use these types. No PHP runtime is involved.

Versioning

SemVer, 0.x: a minor version may break the API. MSRV is Rust 1.99. SpeedySpec's own version (ADR-028) is the PHP runtime's major, not this crate's.

License

MIT