{"id":23416221,"url":"https://github.com/bluk/json-feed-model","last_synced_at":"2025-04-09T06:43:53.392Z","repository":{"id":57634648,"uuid":"302436546","full_name":"bluk/json-feed-model","owner":"bluk","description":"A Rust implementation of JSON Feed model types using Serde JSON.","archived":false,"fork":false,"pushed_at":"2025-03-17T02:55:51.000Z","size":53,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"trunk","last_synced_at":"2025-03-17T03:03:25.278Z","etag":null,"topics":["feed","feeds","json-feed","jsonfeed","rust","serde","serde-json","syndication"],"latest_commit_sha":null,"homepage":"https://docs.rs/json-feed-model/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bluk.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-10-08T19:03:20.000Z","updated_at":"2025-03-17T02:52:57.000Z","dependencies_parsed_at":"2022-09-26T20:20:39.516Z","dependency_job_id":null,"html_url":"https://github.com/bluk/json-feed-model","commit_stats":{"total_commits":13,"total_committers":1,"mean_commits":13.0,"dds":0.0,"last_synced_commit":"bcd20af88a350b24cb9ef96a6f59630f541ab5e9"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluk%2Fjson-feed-model","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluk%2Fjson-feed-model/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluk%2Fjson-feed-model/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bluk%2Fjson-feed-model/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bluk","download_url":"https://codeload.github.com/bluk/json-feed-model/tar.gz/refs/heads/trunk","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247994102,"owners_count":21030049,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["feed","feeds","json-feed","jsonfeed","rust","serde","serde-json","syndication"],"created_at":"2024-12-22T22:14:03.383Z","updated_at":"2025-04-09T06:43:53.374Z","avatar_url":"https://github.com/bluk.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSON Feed Model\n\n[JSON Feed][jsonfeed] Model provides types which can be used to manipulate JSON\nFeed data.\n\nThe crate is basically a [newtype][newtype] wrapper around [Serde\nJSON][serde_json]'s `Map` type and provides methods to JSON Feed properties.\n\nFor example, a library user can have a slice of bytes and create a `Feed` by\ncalling `from_slice`. If the slice of bytes is a JSON object, then a `Feed`\ninstance is returned. The only guarantee which `Feed` and other model types make\nis that the JSON data is a JSON object.\n\nThe library user can call `is_valid(Version::Version1_1)` on the `Feed` instance\nto determine if the JSON object is a valid Version 1.1 JSON Feed.\n\n## Documentation\n\n* [Latest API Docs][api_docs]\n\n## Installation\n\nBy default, features which depend on the Rust `std` library are included.\n\n```toml\n[dependencies]\njson-feed-model = \"0.2.0\"\n```\n\n### Alloc Only\n\nIf the host environment has an allocator but does not have access to the Rust `std` library:\n\n```toml\n[dependencies]\njson-feed-model = { version = \"0.2.0\", default-features = false, features = [\"alloc\"]}\n```\n\n# Accessor Methods\n\nIf the library user wants to read or write data, then methods like `title()`,\n`set_title(...)`, and `remove_title()` exist on `Feed`.\n\nFor \"getter\" methods, the return type is a `Result\u003cOption\u003ctype\u003e, ...\u003e`.  The\n\"getter\" may fail due to expecting the wrong JSON type. For instance, if a field\nis expected to be a JSON string but the value is a JSON number, then an\n`Error::UnexpectedType` will be returned. The field value may or may not be\npresent so the `Option` type is used to indicate if a value exists.\n\nFor \"setter\" and \"remove\" methods, any existing value in the JSON object is\nreturned.\n\n# Owned, Borrowed, and Borrowed Mutable Types\n\nThere are 3 variants of every model type, the \"owned\" data type (e.g. `Feed`),\nthe borrowed data type (e.g.  `FeedRef`), and the borrowed mutable data type\n(e.g. `FeedMut`). In most cases, the \"owned\" data type will be the primary kind\nexplicitly used. The borrowed and borrowed mutable variants may be returned from\n\"getter\" methods for performance reasons.\n\nA few standard traits are implemented like `From\u003cMap\u003cString,Value\u003e\u003e` and\n`Serialize` as well as a few helper methods like `as_map()` and `as_map_mut()`\nfor the model types.\n\n## Examples\n\nThe following example shows how to read properties.\n\n```rust\nuse json_feed_model::{Feed, ItemRef, Version};\n\nlet json = serde_json::json!({\n    \"version\": \"https://jsonfeed.org/version/1.1\",\n    \"title\": \"Lorem ipsum dolor sit amet.\",\n    \"home_page_url\": \"https://example.org/\",\n    \"feed_url\": \"https://example.org/feed.json\",\n    \"items\": [\n        {\n            \"id\": \"cd7f0673-8e81-4e13-b273-4bd1b83967d0\",\n            \"content_text\": \"Aenean tristique dictum mauris, et.\",\n            \"url\": \"https://example.org/aenean-tristique\"\n        },\n        {\n            \"id\": \"2bcb497d-c40b-4493-b5ae-bc63c74b48fa\",\n            \"content_html\": \"Vestibulum non magna vitae tortor.\",\n            \"url\": \"https://example.org/vestibulum-non\"\n        }\n    ]\n});\n\nlet feed = json_feed_model::from_value(json)?;\n\nassert!(feed.is_valid(\u0026Version::Version1_1));\n\nassert_eq!(feed.version()?, Some(json_feed_model::VERSION_1_1));\nassert_eq!(feed.title()?, Some(\"Lorem ipsum dolor sit amet.\"));\nassert_eq!(feed.home_page_url()?, Some(\"https://example.org/\"));\nassert_eq!(feed.feed_url()?, Some(\"https://example.org/feed.json\"));\n\nlet items: Option\u003cVec\u003cItemRef\u003e\u003e = feed.items()?;\nassert!(items.is_some());\nlet items: Vec\u003cItemRef\u003e = items.unwrap();\nassert_eq!(items.len(), 2);\n\nassert_eq!(items[0].id()?, Some(\"cd7f0673-8e81-4e13-b273-4bd1b83967d0\"));\nassert_eq!(\n    items[0].content_text()?,\n    Some(\"Aenean tristique dictum mauris, et.\")\n);\nassert_eq!(\n    items[0].url()?,\n    Some(\"https://example.org/aenean-tristique\")\n);\n\nassert_eq!(items[1].id()?, Some(\"2bcb497d-c40b-4493-b5ae-bc63c74b48fa\"));\nassert_eq!(\n    items[1].content_html()?,\n    Some(\"Vestibulum non magna vitae tortor.\")\n);\nassert_eq!(items[1].url()?, Some(\"https://example.org/vestibulum-non\"));\n# Ok::\u003c(), json_feed_model::Error\u003e(())\n```\n\n### Custom Extension\n\nThe following example uses a custom trait to write and then read a custom extension.\nIt also shows a simple way to use `serde_json` to write the JSON Feed. See\n`serde_json` for other serialization methods.\n\n```rust\nuse json_feed_model::{Feed, Item, Version};\nuse serde_json::Value;\n\ntrait ExampleExtension {\n    fn example(\u0026self) -\u003e Result\u003cOption\u003c\u0026str\u003e, json_feed_model::Error\u003e;\n\n    fn set_example\u003cT\u003e(\u0026mut self, value: T) -\u003e Option\u003cValue\u003e\n    where\n        T: ToString;\n}\n\nimpl ExampleExtension for Feed {\n    fn example(\u0026self) -\u003e Result\u003cOption\u003c\u0026str\u003e, json_feed_model::Error\u003e {\n        self.as_map().get(\"_example\").map_or_else(\n            || Ok(None),\n            |value| match value {\n                Value::String(s) =\u003e Ok(Some(s.as_str())),\n                _ =\u003e Err(json_feed_model::Error::UnexpectedType),\n            },\n        )\n    }\n\n    fn set_example\u003cT\u003e(\u0026mut self, value: T) -\u003e Option\u003cValue\u003e\n    where\n        T: ToString,\n    {\n        self.as_map_mut()\n            .insert(String::from(\"_example\"), Value::String(value.to_string()))\n    }\n}\n\nlet mut feed = Feed::new();\nfeed.set_version(Version::Version1_1);\nfeed.set_title(\"Lorem ipsum dolor sit amet.\");\n\nfeed.set_example(\"123456\");\n\nlet mut item = Item::new();\nitem.set_id(\"2bcb497d-c40b-4493-b5ae-bc63c74b48fa\");\nitem.set_content_text(\"Vestibulum non magna vitae tortor.\");\nitem.set_url(\"https://example.org/vestibulum-non\");\n\nfeed.set_items(vec![item]);\n\nassert!(feed.is_valid(\u0026Version::Version1_1));\n\nlet expected_json = serde_json::json!({\n    \"version\": \"https://jsonfeed.org/version/1.1\",\n    \"title\": \"Lorem ipsum dolor sit amet.\",\n    \"_example\": \"123456\",\n    \"items\": [\n        {\n            \"id\": \"2bcb497d-c40b-4493-b5ae-bc63c74b48fa\",\n            \"content_text\": \"Vestibulum non magna vitae tortor.\",\n            \"url\": \"https://example.org/vestibulum-non\",\n        }\n    ]\n});\nassert_eq!(feed, json_feed_model::from_value(expected_json)?);\n\nassert_eq!(feed.example()?, Some(\"123456\"));\n\nlet output = serde_json::to_string(\u0026feed);\nassert!(output.is_ok());\n# Ok::\u003c(), json_feed_model::Error\u003e(())\n```\n\n## License\n\nLicensed under either of [Apache License, Version 2.0][license_apache] or [MIT\nLicense][license_mit] at your option.\n\n### Contributions\n\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be\ndual licensed as above, without any additional terms or conditions.\n\n[license_apache]: LICENSE-APACHE\n[license_mit]: LICENSE-MIT\n[jsonfeed]: https://jsonfeed.org/\n[newtype]: https://doc.rust-lang.org/rust-by-example/generics/new_types.html\n[serde_json]: https://github.com/serde-rs/json\n[api_docs]: https://docs.rs/json-feed-model/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbluk%2Fjson-feed-model","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbluk%2Fjson-feed-model","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbluk%2Fjson-feed-model/lists"}