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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
// Regression guard for issue #456/#460: parser helpers were refactored to keep
// every function under clippy's default 7-argument threshold via XmlCtx/EntryCtx/*Ctx
// context structs. `forbid` (not `deny`) so a future `#[allow(clippy::too_many_arguments)]`
// can't silently opt back out. A crate-level attribute (not a Cargo.toml lints table
// entry) so `[lints] workspace = true` keeps inheriting the full workspace rust+clippy
// lint sets unmodified — this crate has no proc-macro-generated `#[allow(clippy::all)]`
// (unlike feedparser-rs-node's `#[napi]`), so `forbid` is safe here.
// Public API growth guard (#637): a public struct with all-public fields or a public enum
// must be `#[non_exhaustive]`, or carry an `#[expect]` explaining why it is deliberately closed.
//! # feedparser-rs: High-performance RSS/Atom/JSON Feed parser
//!
//! A pure Rust implementation of feed parsing with API compatibility for Python's
//! [feedparser](https://github.com/kurtmckee/feedparser) library. Designed for
//! 10-100x faster feed parsing with identical behavior.
//!
//! ## Quick Start
//!
//! ```
//! use feedparser_rs::parse;
//!
//! let xml = r#"
//! <?xml version="1.0"?>
//! <rss version="2.0">
//! <channel>
//! <title>Example Feed</title>
//! <link>https://example.com</link>
//! <item>
//! <title>First Post</title>
//! <link>https://example.com/post/1</link>
//! </item>
//! </channel>
//! </rss>
//! "#;
//!
//! let feed = parse(xml.as_bytes()).unwrap();
//! assert!(!feed.bozo);
//! assert_eq!(feed.feed.title.as_deref(), Some("Example Feed"));
//! assert_eq!(feed.entries.len(), 1);
//! ```
//!
//! ## Supported Formats
//!
//! | Format | Versions | Detection |
//! |--------|----------|-----------|
//! | RSS | 0.91 - 0.94, 2.x | `<rss>` element |
//! | RSS 1.0, 0.90 | RDF-based | `<rdf:RDF>` root |
//! | Atom | 0.3, 1.0 | `<feed>` with Atom namespace |
//! | JSON Feed | 1.0, 1.1 | `version` field equal to `https://jsonfeed.org/version/1` or `https://jsonfeed.org/version/1.1` |
//!
//! ## Namespace Extensions
//!
//! The parser supports common feed extensions:
//!
//! - **iTunes/Podcast** (`itunes:`) - Podcast metadata, categories, explicit flags
//! - **Podcast 2.0** (`podcast:`) - Transcripts, chapters, funding, persons
//! - **Dublin Core** (`dc:`) - Creator, date, rights, subject
//! - **Media RSS** (`media:`) - Thumbnails, content, descriptions
//! - **Content** (`content:encoded`) - Full HTML content
//! - **Syndication** (`sy:`) - Update frequency hints
//! - **`GeoRSS`** (`georss:`) - Geographic coordinates
//! - **Creative Commons** (`cc:`, `creativeCommons:`) - License information
//!
//! ## Type-Safe URL and MIME Handling
//!
//! The library uses semantic newtypes for improved type safety:
//!
//! ```
//! use feedparser_rs::{Url, MimeType, Email};
//!
//! // Url - wraps URL strings without validation (bozo-compatible)
//! let url = Url::new("https://example.com/feed.xml");
//! assert_eq!(url.as_str(), "https://example.com/feed.xml");
//! assert!(url.starts_with("https://")); // Deref to str
//!
//! // MimeType - uses Arc<str> for efficient cloning
//! let mime = MimeType::new("application/rss+xml");
//! let clone = mime.clone(); // Cheap: just increments refcount
//!
//! // Email - wraps email addresses
//! let email = Email::new("author@example.com");
//! ```
//!
//! These types implement <code>[`Deref`](std::ops::Deref)<Target=str></code>, so string methods work directly:
//!
//! ```
//! use feedparser_rs::Url;
//!
//! let url = Url::new("https://example.com/path?query=1");
//! assert!(url.contains("example.com"));
//! assert_eq!(url.len(), 32);
//! ```
//!
//! ## The Bozo Pattern
//!
//! Following Python feedparser's philosophy, this library **never panics** on
//! malformed input. Instead, it sets the `bozo` flag and continues parsing:
//!
//! ```
//! use feedparser_rs::parse;
//!
//! // XML with undefined entity - triggers bozo
//! let xml_with_entity = b"<rss version='2.0'><channel><title>Test </title></channel></rss>";
//!
//! let feed = parse(xml_with_entity).unwrap();
//! // Parser handles invalid characters gracefully
//! assert!(feed.feed.title.is_some());
//! ```
//!
//! The bozo flag indicates the feed had issues but was still parseable.
//!
//! ## Resource Limits
//!
//! Protect against malicious feeds with [`ParserLimits`]:
//!
//! ```
//! use feedparser_rs::{parse_with_limits, ParserLimits};
//!
//! // Customize limits for untrusted input
//! let limits = ParserLimits::default()
//! .with_max_entries(100)
//! .with_max_text_length(50_000);
//!
//! let xml = b"<rss version='2.0'><channel><title>Safe</title></channel></rss>";
//! let feed = parse_with_limits(xml, limits).unwrap();
//! ```
//!
//! ## HTTP Fetching
//!
//! With the `http` feature (enabled by default), fetch feeds from URLs:
//!
//! ```no_run
//! use feedparser_rs::parse_url;
//!
//! // Simple fetch
//! let feed = parse_url("https://example.com/feed.xml", None, None, None)?;
//!
//! // With conditional GET for caching
//! let feed2 = parse_url(
//! "https://example.com/feed.xml",
//! feed.etag.as_deref(), // ETag from previous fetch
//! feed.modified.as_deref(), // Last-Modified from previous fetch
//! Some("MyApp/1.0"), // Custom User-Agent
//! )?;
//!
//! if feed2.status == Some(304) {
//! println!("Feed not modified since last fetch");
//! }
//! # Ok::<(), feedparser_rs::FeedError>(())
//! ```
//!
//! ## Core Types
//!
//! - [`ParsedFeed`] - Complete parsed feed with metadata and entries
//! - [`FeedMeta`] - Feed-level metadata (title, link, author, etc.)
//! - [`Entry`] - Individual feed entry/item
//! - [`Link`], [`Person`], [`Tag`] - Common feed elements
//! - [`Url`], [`MimeType`], [`Email`] - Type-safe string wrappers
//!
//! ## Module Structure
//!
//! - [`types`] - All data structures for parsed feeds
//! - [`namespace`] - Handlers for namespace extensions (iTunes, Podcast 2.0, etc.)
//! - [`util`] - Helper functions for dates, HTML sanitization, encoding
//! - [`compat`] - Python feedparser API compatibility layer
//! - [`http`] - HTTP client for fetching feeds (requires `http` feature)
/// Compatibility utilities for Python feedparser API
/// HTTP client module for fetching feeds from URLs
/// Namespace handlers for extended feed formats
/// Type definitions for feed data structures
///
/// This module contains all the data types used to represent parsed feeds,
/// including the main `ParsedFeed` struct and related types.
/// Utility functions for feed parsing
///
/// This module provides helper functions for date parsing, HTML sanitization,
/// and encoding detection that are useful for feed processing.
pub use UrlParseError;
pub use ;
pub use ;
pub use ParseOptions;
pub use ;
pub use ;
pub use ;
pub use ;
pub use SsrfRejection;
/// Parse feed from HTTP/HTTPS URL
///
/// Fetches the feed from the given URL and parses it. Supports conditional GET
/// using `ETag` and `Last-Modified` headers for bandwidth-efficient caching.
///
/// # Arguments
///
/// * `url` - HTTP or HTTPS URL to fetch
/// * `etag` - Optional `ETag` from previous fetch for conditional GET
/// * `modified` - Optional `Last-Modified` timestamp from previous fetch
/// * `user_agent` - Optional custom User-Agent header
///
/// # Returns
///
/// Returns a `ParsedFeed` with HTTP metadata fields populated:
/// - `status`: HTTP status code (200, 304, etc.)
/// - `href`: Final URL after redirects
/// - `etag`: `ETag` header value (for next request)
/// - `modified`: `Last-Modified` header value (for next request)
/// - `headers`: Full HTTP response headers
///
/// On 304 Not Modified, returns a feed with empty entries but status=304.
///
/// # Errors
///
/// Returns `FeedError::Fetch` with a [`http::FetchError`] if:
/// - The URL is invalid (`InvalidUrl`) or targets a blocked address, including a
/// redirect hop (`BlockedAddress`)
/// - More than 10 redirects are followed (`TooManyRedirects`)
/// - The HTTP status is 4xx or 5xx (`Status`; 304 is not an error)
/// - The decompressed body exceeds `max_feed_size_bytes` (`BodyTooLarge`, 100 MB by default)
/// - A conditional-request header value is invalid (`InvalidHeader`)
/// - Any other network error occurs (`Transport`)
///
/// Other [`FeedError`] variants report a failure to parse the fetched body.
///
/// # Examples
///
/// ```no_run
/// use feedparser_rs::parse_url;
///
/// // First fetch
/// let feed = parse_url("https://example.com/feed.xml", None, None, None).unwrap();
/// println!("Title: {:?}", feed.feed.title);
/// println!("ETag: {:?}", feed.etag);
///
/// // Subsequent fetch with caching
/// let feed2 = parse_url(
/// "https://example.com/feed.xml",
/// feed.etag.as_deref(),
/// feed.modified.as_deref(),
/// None
/// ).unwrap();
///
/// if feed2.status == Some(304) {
/// println!("Feed not modified, use cached version");
/// }
/// ```
/// Parse feed from URL with custom parser limits
///
/// Like `parse_url` but allows specifying custom limits for resource control.
/// HTML sanitization and relative URI resolution use their
/// [`ParseOptions::default`] settings (both enabled); use
/// [`parse_url_with_options`] to control them directly.
///
/// # Errors
///
/// Returns `FeedError::Fetch` if the request fails (see [`parse_url`]) or another
/// [`FeedError`] if parsing fails.
///
/// # Examples
///
/// ```no_run
/// use feedparser_rs::{parse_url_with_limits, ParserLimits};
///
/// let limits = ParserLimits::strict();
/// let feed = parse_url_with_limits(
/// "https://example.com/feed.xml",
/// None,
/// None,
/// None,
/// limits
/// ).unwrap();
/// ```
/// Parse feed from URL with full control over parser behavior
///
/// Like `parse_url` but allows specifying HTML sanitization, relative URI
/// resolution, and resource limits via [`ParseOptions`]. The download stops once the
/// decompressed body exceeds `options.limits.max_feed_size_bytes`.
///
/// The `charset` of the response `Content-Type` takes part in decoding: it ranks
/// below a byte order mark and above the XML declaration, is ignored for JSON
/// bodies, and gives way to UTF-8 or the XML declaration (setting `bozo`) when the
/// bytes contradict it.
///
/// # Errors
///
/// Returns `FeedError::Fetch` if the request fails (see [`parse_url`]) or another
/// [`FeedError`] if parsing fails.
///
/// # Examples
///
/// ```no_run
/// use feedparser_rs::{parse_url_with_options, ParseOptions};
///
/// let options = ParseOptions::default().with_sanitize_html(false);
/// let feed = parse_url_with_options(
/// "https://example.com/feed.xml",
/// None,
/// None,
/// None,
/// &options,
/// ).unwrap();
/// ```
/// Fetches through `client`, bounding the download like the parser input, and parses.
/// Parses a successful response and carries its HTTP metadata into the feed.
/// Parse `data` as if served with `content_type`; entry point of the `encoding` fuzz target.
///
/// # Errors
///
/// Same as [`parse_with_options`].