1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//! Serde integration for Surfing.
//!
//! This module provides integration with the Serde ecosystem, allowing
//! direct deserialization of JSON extracted from mixed text content.
//!
//! # Feature Flag
//!
//! This module is only available when the `serde` feature is enabled:
//!
//! ```toml
//! [dependencies]
//! surfing = { version = "0.1.0", features = ["serde"] }
//! ```
//!
//! # Single-Step Deserialization
//!
//! ```
//! # #[cfg(feature = "serde")]
//! # {
//! use serde::Deserialize;
//! use surfing::serde::from_mixed_text;
//!
//! #[derive(Debug, Deserialize, PartialEq)]
//! struct LogEntry {
//! level: String,
//! message: String,
//! }
//!
//! let text = "Log entry: {\"level\":\"info\",\"message\":\"Server started\"} End of line";
//! let entry: LogEntry = from_mixed_text(text).unwrap();
//!
//! assert_eq!(entry, LogEntry {
//! level: "info".to_string(),
//! message: "Server started".to_string(),
//! });
//! # }
//! ```
//!
//! # Streaming Deserialization
//!
//! For streaming use cases, the `StreamingDeserializer` provides a higher-level API:
//!
//! ```
//! # #[cfg(feature = "serde")]
//! # {
//! use serde::Deserialize;
//! use surfing::serde::StreamingDeserializer;
//!
//! #[derive(Debug, Deserialize, PartialEq)]
//! struct User {
//! id: u64,
//! name: String,
//! }
//!
//! // Create a deserializer for the User type
//! let mut deserializer = StreamingDeserializer::<User>::new();
//!
//! // Process chunks as they arrive
//! let chunks = [
//! "Text {\"id\":",
//! "42,\"name\":\"Alice\"}",
//! ];
//!
//! let result = deserializer.process_chunk(chunks[0]);
//! assert!(result.is_none()); // Incomplete JSON
//!
//! let result = deserializer.process_chunk(chunks[1]);
//! assert!(result.is_some());
//!
//! let user = result.unwrap();
//! assert_eq!(user.id, 42);
//! # }
//! ```
pub use from_mixed_text;
pub use from_mixed_text_with_parser;
pub use DeserializeError;
pub use StreamingDeserializer;