Skip to content

Commit

Permalink
Merge pull request #627 from Stremio/chore/update-docs
Browse files Browse the repository at this point in the history
Chore/update docs
  • Loading branch information
elpiel authored Jan 24, 2024
2 parents 9b0b073 + 94f8291 commit 80a06b6
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[build]
# for `--enable-index-page` it is required to pass `-Z unstable-options` to rustdocs
# rustdocflags = ["--cfg", "docsrs", "-Z", "unstable-options", "--enable-index-page"]

[alias]
build-docs = "doc --no-deps --workspace --document-private-items"

2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Build docs
# Building locally:
# for `--enable-index-page` it is required to pass `-Z unstable-options` to rustdocs
run: RUSTDOCFLAGS="--cfg docsrs -Z unstable-options --enable-index-page" cargo +nightly doc --all-features --no-deps --workspace
run: RUSTDOCFLAGS="--cfg docsrs -Z unstable-options --enable-index-page" cargo +nightly build-docs

- name: Prepare /docs
run: |
Expand Down
3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ members = [
"stremio-watched-bitfield",
]

[lib]
doctest = false

[features]
# TODO: env-future-send should be enabled by default
# but our `TestEnv` for `unit_tests` uses a MutexGuard which is not Send.
Expand Down
66 changes: 65 additions & 1 deletion src/types/addon/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,50 @@ pub struct Manifest {
#[serde_as(deserialize_as = "DefaultOnError<NoneAsEmptyString>")]
pub background: Option<Url>,
pub types: Vec<String>,
/// # Resources
///
/// # Examples
///
/// ## Short format
/// ```
/// use std::vec::Vec;
/// use stremio_core::types::addon::ManifestResource;
///
/// let manifest_resources_short = serde_json::json!({
/// // Addon manifest.json ....
///
/// // short-format of resources:
/// "resources": ["catalog", "meta", "subtitles"],
/// }).get("resources").unwrap().clone();
///
/// let resources = serde_json::from_value::<Vec<ManifestResource>>(manifest_resources_short).expect("Failed to deserialize ManifestResource");
/// ```
///
/// ## Long format
///
/// ```
/// use std::vec::Vec;
/// use stremio_core::types::addon::ManifestResource;
///
/// let manifest_resources_long = serde_json::json!({
/// // Addon manifest.json ....
///
/// // long-format of resources:
/// "resources": [
/// {
/// "name": "catalog",
/// // optional, i.e. can be null
/// "types": ["anime", "series", "movies"],
/// // optional, i.e. can be null
/// "idPrefixes": ["tt", "kitsu"],
/// },
/// "meta",
/// "subtitles"
/// ]
/// }).get("resources").unwrap().clone();
///
/// let resources = serde_json::from_value::<Vec<ManifestResource>>(manifest_resources_long).expect("Failed to deserialize ManifestResource");
/// ```
pub resources: Vec<ManifestResource>,
pub id_prefixes: Option<Vec<String>>,
#[serde(default)]
Expand Down Expand Up @@ -155,6 +199,24 @@ impl ManifestCatalog {
});
all_supported && required_satisfied
}
pub fn are_extra_names_supported(&self, extra_names: &[String]) -> bool {
let all_supported = extra_names.iter().all(|extra_name| {
self.extra
.iter()
.any(|extra_prop| &extra_prop.name == extra_name)
});
let required_satisfied = self
.extra
.iter()
.filter(|extra_prop| extra_prop.is_required)
.all(|extra_prop| {
extra_names
.iter()
.any(|extra_name| extra_name == &extra_prop.name)
});
all_supported && required_satisfied
}

pub fn default_required_extra(&self) -> Option<Vec<ExtraValue>> {
self.extra
.iter()
Expand Down Expand Up @@ -231,6 +293,8 @@ pub struct ExtraProp {
#[serde(default)]
#[serde_as(deserialize_as = "DefaultOnNull")]
pub options: Vec<String>,

/// The maximum options that should be passed for this addon extra property.
#[serde(default)]
pub options_limit: OptionsLimit,
}
Expand Down Expand Up @@ -269,7 +333,7 @@ impl<'de> DeserializeAs<'de, ExtraProp> for ExtraPropValid {
}
}

#[derive(Clone, Deref, PartialEq, Eq, Serialize, Deserialize, Debug)]
#[derive(Clone, Copy, Deref, PartialEq, Eq, Serialize, Deserialize, Debug)]
pub struct OptionsLimit(pub usize);

impl Default for OptionsLimit {
Expand Down

0 comments on commit 80a06b6

Please sign in to comment.