mirror of
https://github.com/storytold/lightcraft.git
synced 2026-12-04 07:51:17 -05:00
8972565249
* LR-PROF-IMPORT: import the user's own DNG camera profiles (.dcp)
profile.import (File > Import Profiles & Presets, drag & drop) now also
reads DNG Camera Profiles: the user's own .dcp files, e.g. made with a
colour-checker tool. They appear in the profile browser and menu under
Camera Profiles with dcp:<camera>-<file> ids; profiles.camera lists them
and profile.deleteCamera / profile.deleteImported remove them. A library
on disk keeps a copy in Profiles/. No profile ships with the app and the
repository holds none: tests build theirs in memory (write_dcp).
lightcraft_raw::dcp parses the file per DNG spec ch. 6 (magic RC in
place of 42; IFD 0 read through the existing DNG colour builders) and
DcpProfile::applied_to puts its matrices, illuminants and look in place
of a raw file's, keeping the shot's white balance, analog balance and
baseline exposure.
Choosing one (develop.profile) replaces the raw file's colour model when
it is decoded, before the starting colour and the white-balance scale
(WbScaleOf) are worked out, so the matrix path takes over from the fitted
JPEG look (CR3/CR2/ARW...) and white balance follows the profile. A
profile without a tone curve of its own (most chart-made ones) keeps the
photo's contrast: the DNG's tone curve, else the tone of the camera-JPEG
fit. The profile travels with SourceRef::File into FileLoader /
PairLoader (new Option<&DcpProfile> argument); a decoded source records
the profile it was made with and is not reused for another. Smart
previews and the web render worker keep the file's own colour; rendered
(non-raw) photos ignore it.
This reverses the documented "Adobe profile formats deliberately
unsupported" stance for user-supplied files only; docs updated.
Split out of #1012.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: build against upstream main (kelvin_presets, 3-arg loaders)
DcpProfile::applied_to keeps the file's white-balance presets (new
ColorData::kelvin_presets upstream): they are camera facts like as-shot
neutral. Upstream's new FileLoader test closures take the profile argument.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: hover previews and browser thumbnails develop the hovered camera profile
The loupe's hover preview (preview_job) and the profile browser's thumbnails (variant_job) took
the photo's own decoded source, so hovering an imported camera profile showed the built-in colour
(and hovering a built-in profile while one was applied kept the camera profile's). Both now decode
as the hovered settings develop: the source follows the settings' camera profile, as the main
render does, and a variant's cache key already follows its settings.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: build against upstream main (face-tile test loader and render_bench take the camera profile)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* CI: the catalog's staging-link test module is Unix-only (unused import broke clippy on Windows)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* CI: same-folder export test expects the '/'-joined subfolder (failed on Windows)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* CI: folder-drop tests build widget ids with the Folders tree's '/' paths (failed on Windows)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: rustfmt after merging main
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: a real D750 camera profile as a pinned test corpus, checked against Lightroom
dieli's CC0 Nikon D750 ColorChecker set (Calibrite PROFILER dual-illuminant DCP,
matrix-only; the two chart NEFs; Lightroom Classic 15.6 renders with the profile)
is fetched by cargo xtask corpus --download into corpus/d750-colorchecker/, pinned
to commit f37f4054 and by sha256; nothing is committed.
Tests (skip without the corpus): the profile parses as matrix-only with
Cool White Fluorescent + D55; the matrices blend by inverse temperature; the
matrix-only path inverts the colour matrix and adapts to D50; it takes over the
chart NEFs' colour; imported and applied end to end, the charts develop within
mean dE2000 3.84 (flash) / 3.35 (indoor) of Lightroom's renders.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: a single .dcp file is a camera profile only, not also an unreadable LUT
profile.import read every plain file that was neither a folder nor a .zip as a .cube LUT, so importing
one .dcp imported the camera profile and also reported it as failed ("stream did not contain valid
UTF-8"). Only .cube files are read as LUTs now.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: review fixes for imported camera profiles
- A library moved or restored elsewhere finds its camera profiles in its own Profiles/ folder.
- A grid thumbnail is cut from the decoded preview only when that preview used the same camera profile.
- Render and source cache keys carry a fingerprint of the profile file, so a deleted or replaced profile never
has its old renders stand in.
- Camera profiles can be favourites, and favourites/recent entries survive reopening the library.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: smart previews without the camera profile, current-profile source facts, unsupported files reported
CodeRabbit review of 4ef025d9:
- Build Smart Previews develops the proxy without the photo's imported camera profile and never takes a cached
source decoded with it (the denoised picture is kept); before, only the stale-proxy refresh left it out.
- Session::source_info reports decoder facts only from a cached source developed with the camera profile the
photo uses now, else the catalog's.
- profile.import reports a file that is neither .cube, .dcp nor .zip as failed instead of passing over it.
Each with a regression test in tests_dcp.rs.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: the Before side decodes with its own camera profile; a failed profile copy fails that file only
- build_job (and region_job_before through it) picks the Before render's source with the Before
settings, so it never reuses or decodes a source developed with the edit's camera profile.
- profile.import: a .dcp whose copy into the library fails is reported in `failed`; the profiles
imported with it stay imported and are saved, and nothing half-written is left.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: a cached smart preview stands in while the original is offline
A smart preview carries no camera profile, so with an imported profile the profile check
rejected the cached proxy and every render decoded it again (it gives the same picture). It
now stands in, for its own level and for the thumbnail cut from it, while the original is
known to be offline; otherwise the profile check is as before, so once the original is back
the photo is decoded from it with its profile. Photos without an imported profile keep main's
behaviour. Test `tests_dcp::a_cached_smart_preview_stands_in_while_the_original_is_offline`
(fails without the fix).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: deleting a camera profile removes the library's copy before forgetting it
profile.deleteCamera now removes the library's copy of the profile file
first. A copy that is already gone is fine; any other error (file in use,
no access) fails the command and keeps the profile listed, so the library
never holds a profile file it no longer lists. Test:
a_profile_whose_copy_cannot_be_deleted_stays.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: deleting a camera profile never follows `..` out of the profiles folder
A listed path with a `..` component can start with the profiles folder and
still lead out of it; such a path is not treated as the library's copy, so
deleting the profile leaves that file alone. Test:
deleting_a_profile_never_follows_dot_dot_out_of_the_profiles_folder.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: both tone fits of a DNG see its lens opcodes; no side effect in the profile-tag comparison
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: a hover preview's key carries the camera profile file's fingerprint
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: unusable camera profiles not offered; file's WB scale and the profile's tone kept
Review of #1063 (CodeRabbit, outside-diff findings):
- a camera profile whose file is missing or damaged when the library opens
is no longer offered in the profile browser or accepted by develop.profile
(it silently developed with the raw's own colour); the entry stays, so it is
offered again once the file is back.
- a raw on the relative white-balance scale stays relative with a camera
profile (its matrices turned it to Kelvin, so existing edits were read as
absolute temperatures and the catalog and quick previews disagreed).
- with a camera profile its tone curve, then the tone kept for a curve-less
profile, come before the fitted camera look's tone.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: one Camera Profiles group; the web loader keeps a raw's own colour
Review of #1063 (CodeRabbit):
- a LUT group named "Camera Profiles" that didn't sort last made the profile
menu list that group twice; it is now one group, last, with both kinds.
- without web workers a render ran inline and the web loader applied the
selected camera profile, unlike the worker (the documented web behaviour
keeps the raw's own colour); the loader now leaves it out.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: camera profile files are read at most to the 64 MiB limit
A .dcp larger than the parser accepts was read whole into memory before
being refused. One bounded read (lightcraft_raw::dcp::read_dcp) stops one
byte past the limit and is used for import, reopening a library and the
duplicate check.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* LR-PROF-IMPORT: a test that a hostile hue/saturation map header in a camera profile drops the map (FredApps, #1063)
Dimensions far past the data, past u32 products or zero, an entry count of 4 billion values and a
data offset past the end each drop the map while the profile's matrix still reads.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Docs: parity checklist keeps both sides of the merge
* LR-PROF-IMPORT: tests added on main take the file loader's camera-profile argument
* Merge main; a thumbnail test takes the file loader's camera-profile argument
* Docs: one camera colour row, with main's notes and the import note
* Process key tests take the profile salt argument
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: FredApps <153173854+FredApps@users.noreply.github.com>
304 lines
11 KiB
Rust
304 lines
11 KiB
Rust
//! The command registry.
|
|
//!
|
|
//! Command ids group by area: `library.*` (view/selection), `photo.*` (rating, flags, rotate,
|
|
//! delete), `album.*`, `develop.*` (settings), `crop.*`, `mask.*`, `preset.*`, `version.*`,
|
|
//! `edit.*` (undo/redo), and queries (`catalog.query`, `photo.inspect`, `develop.get`…).
|
|
|
|
mod activity;
|
|
mod before;
|
|
pub(crate) mod browse;
|
|
mod color;
|
|
pub(crate) mod convert;
|
|
mod cull;
|
|
pub mod curves;
|
|
pub mod dcp_profiles;
|
|
pub(crate) mod denoise;
|
|
mod develop;
|
|
mod edit;
|
|
mod export;
|
|
pub(crate) mod face_detect;
|
|
mod face_models;
|
|
mod face_recognize;
|
|
pub mod filters;
|
|
mod focus;
|
|
pub mod geocode;
|
|
pub mod keywords;
|
|
pub mod lens_refresh;
|
|
pub mod library;
|
|
pub mod lut_profiles;
|
|
pub mod manage;
|
|
pub mod mask_effect_files;
|
|
pub mod mask_effects;
|
|
mod masks;
|
|
mod merge;
|
|
pub mod metadata;
|
|
pub mod missing;
|
|
mod organize;
|
|
mod prefs;
|
|
mod preset_files;
|
|
pub mod previews;
|
|
mod print;
|
|
mod query;
|
|
pub mod recheck;
|
|
pub mod reload;
|
|
pub mod similar;
|
|
mod slideshow;
|
|
mod sync;
|
|
mod xmp;
|
|
|
|
use serde::Serialize;
|
|
use serde_json::Value;
|
|
|
|
use crate::{EngineError, Result, Session};
|
|
|
|
pub type Run = fn(&mut Session, &Value) -> Result<Value>;
|
|
pub type Enabled = fn(&Session) -> std::result::Result<(), String>;
|
|
|
|
pub struct CommandSpec {
|
|
pub id: &'static str,
|
|
pub label: &'static str,
|
|
/// Menu placement (`["Photo", "Rotate"]`); empty = not in menus.
|
|
pub menu: &'static [&'static str],
|
|
/// Default shortcut (`Cmd+Shift+C`), mapped per platform by the UI.
|
|
pub shortcut: Option<&'static str>,
|
|
/// Human/agent-readable parameter description.
|
|
pub params: &'static str,
|
|
pub enabled: Enabled,
|
|
pub run: Run,
|
|
/// Record in the journal (false for queries).
|
|
pub journal: bool,
|
|
/// `enabled` judges the selection (menus, shortcuts); a call that names its photos (`ids` /
|
|
/// `id`, see [`names_photos`]) skips it, and the command validates those photos itself.
|
|
/// Off unless a command opts in (`CommandSpec { explicit_targets: true, ..cmd!(…) }`).
|
|
pub explicit_targets: bool,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Serialize)]
|
|
pub struct CommandInfo {
|
|
pub id: &'static str,
|
|
pub label: &'static str,
|
|
pub menu: Vec<&'static str>,
|
|
pub shortcut: Option<&'static str>,
|
|
pub params: &'static str,
|
|
pub enabled: bool,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub disabled_reason: Option<String>,
|
|
}
|
|
|
|
impl CommandSpec {
|
|
pub fn info(&self, s: &Session) -> CommandInfo {
|
|
let e = (self.enabled)(s);
|
|
CommandInfo {
|
|
id: self.id,
|
|
label: self.label,
|
|
menu: self.menu.to_vec(),
|
|
shortcut: self.shortcut,
|
|
params: self.params,
|
|
enabled: e.is_ok(),
|
|
disabled_reason: e.err(),
|
|
}
|
|
}
|
|
}
|
|
|
|
// ---------- enablement predicates
|
|
|
|
pub fn always(_: &Session) -> std::result::Result<(), String> {
|
|
Ok(())
|
|
}
|
|
pub fn has_active(s: &Session) -> std::result::Result<(), String> {
|
|
s.active().map(|_| ()).ok_or_else(|| "no photo selected".into())
|
|
}
|
|
pub fn has_selection(s: &Session) -> std::result::Result<(), String> {
|
|
if s.selection.ids.is_empty() && s.selection.active.is_none() { Err("no photos selected".into()) } else { Ok(()) }
|
|
}
|
|
/// Albums hold library photos: a selection of only browsed (Local) photos has nothing an album
|
|
/// can take (issue #684; Add to My Photos first).
|
|
pub fn has_library_selection(s: &Session) -> std::result::Result<(), String> {
|
|
has_selection(s)?;
|
|
if s.selected().iter().any(|id| s.catalog.photo(*id).is_none_or(|p| !p.local)) { Ok(()) } else { Err(LOCAL_ONLY.into()) }
|
|
}
|
|
/// Why an album command refused a Local-only selection.
|
|
pub const LOCAL_ONLY: &str = "only Local photos: albums hold library photos (Add to My Photos first)";
|
|
pub fn can_undo(s: &Session) -> std::result::Result<(), String> {
|
|
if s.undo.is_empty() { Err("nothing to undo".into()) } else { Ok(()) }
|
|
}
|
|
pub fn can_redo(s: &Session) -> std::result::Result<(), String> {
|
|
if s.redo.is_empty() { Err("nothing to redo".into()) } else { Ok(()) }
|
|
}
|
|
pub fn has_clipboard(s: &Session) -> std::result::Result<(), String> {
|
|
has_selection(s)?;
|
|
if s.clipboard.is_none() { Err("no settings copied".into()) } else { Ok(()) }
|
|
}
|
|
|
|
macro_rules! cmd {
|
|
($id:literal, $label:literal, [$($m:literal),*], $sc:expr, $params:literal, $en:expr, $run:expr) => {
|
|
$crate::cmd::CommandSpec { id: $id, label: $label, menu: &[$($m),*], shortcut: $sc, params: $params, enabled: $en, run: $run, journal: true, explicit_targets: false }
|
|
};
|
|
(query $id:literal, $label:literal, [$($m:literal),*], $sc:expr, $params:literal, $en:expr, $run:expr) => {
|
|
$crate::cmd::CommandSpec { id: $id, label: $label, menu: &[$($m),*], shortcut: $sc, params: $params, enabled: $en, run: $run, journal: false, explicit_targets: false }
|
|
};
|
|
}
|
|
pub(crate) use cmd;
|
|
|
|
pub fn command_specs() -> &'static [CommandSpec] {
|
|
static SPECS: std::sync::OnceLock<Vec<CommandSpec>> = std::sync::OnceLock::new();
|
|
SPECS.get_or_init(|| {
|
|
let mut v = Vec::new();
|
|
v.extend(edit::specs());
|
|
v.extend(library::specs());
|
|
v.extend(develop::specs());
|
|
v.extend(color::specs());
|
|
v.extend(curves::specs());
|
|
v.extend(masks::specs());
|
|
v.extend(organize::specs());
|
|
v.extend(keywords::specs());
|
|
v.extend(manage::specs());
|
|
v.extend(previews::specs());
|
|
v.extend(lut_profiles::specs());
|
|
v.extend(dcp_profiles::specs());
|
|
v.extend(mask_effects::specs());
|
|
v.extend(cull::specs());
|
|
v.extend(convert::specs());
|
|
v.extend(convert::edit_specs());
|
|
v.extend(merge::specs());
|
|
v.extend(query::specs());
|
|
v.extend(xmp::specs());
|
|
v.extend(preset_files::specs());
|
|
v.extend(prefs::specs());
|
|
v.extend(slideshow::specs());
|
|
v.extend(export::specs());
|
|
v.extend(print::specs());
|
|
v.extend(before::specs());
|
|
v.extend(browse::specs());
|
|
v.extend(missing::specs());
|
|
v.extend(recheck::specs());
|
|
v.extend(lens_refresh::specs());
|
|
v.extend(sync::specs());
|
|
v.extend(metadata::specs());
|
|
v.extend(geocode::specs());
|
|
v.extend(filters::specs());
|
|
v.extend(denoise::specs());
|
|
v.extend(face_models::specs());
|
|
v.extend(face_detect::specs());
|
|
v.extend(face_recognize::specs());
|
|
v.extend(focus::specs());
|
|
v.extend(activity::specs());
|
|
v
|
|
})
|
|
}
|
|
|
|
pub fn find_command(id: &str) -> Option<&'static CommandSpec> {
|
|
command_specs().iter().find(|c| c.id == id)
|
|
}
|
|
|
|
// ---------- param helpers
|
|
|
|
/// The call names its target photos (`ids` or `id`, not null) instead of using the selection.
|
|
pub(crate) fn names_photos(p: &Value) -> bool {
|
|
["ids", "id"].iter().any(|k| p.get(k).is_some_and(|v| !v.is_null()))
|
|
}
|
|
|
|
/// The call names its target photos in `ids`, whatever else it carries in `id` (`album.addPhotos`'s `id` is the album).
|
|
pub(crate) fn names_photo_ids(p: &Value) -> bool {
|
|
p.get("ids").is_some_and(|v| !v.is_null())
|
|
}
|
|
|
|
/// For a command that opts into `explicit_targets` but whose `id` isn't a photo: [`Session::execute`] skipped the
|
|
/// selection check because the call carries an `id`, so the command makes it itself unless `ids` names the photos.
|
|
pub(crate) fn enabled_unless_ids(s: &Session, p: &Value, id: &str, enabled: Enabled) -> Result<()> {
|
|
if names_photo_ids(p) {
|
|
return Ok(());
|
|
}
|
|
enabled(s).map_err(|why| EngineError::Disabled(id.to_string(), why))
|
|
}
|
|
|
|
/// The photos `ids` names: `None` when it is missing or null (the command then falls back to the
|
|
/// selection, or its own default), else every entry as a photo id. An `ids` that isn't a list of
|
|
/// whole numbers is an error, never `None`: falling back would act on the selection instead of
|
|
/// the photos the call meant (`{"ids": 3}`, `{"ids": ["3"]}`).
|
|
pub(crate) fn photo_ids(p: &Value, cmd: &str) -> Result<Option<Vec<lightcraft_catalog::PhotoId>>> {
|
|
match p.get("ids") {
|
|
None | Some(Value::Null) => Ok(None),
|
|
Some(Value::Array(a)) => a
|
|
.iter()
|
|
.map(|v| v.as_u64().map(lightcraft_catalog::PhotoId).ok_or_else(|| bad(cmd, "`ids` must be photo ids (whole numbers)")))
|
|
.collect::<Result<Vec<_>>>()
|
|
.map(Some),
|
|
Some(_) => Err(bad(cmd, "`ids` must be a list of photo ids")),
|
|
}
|
|
}
|
|
|
|
/// The photo `id` names: `None` when it is missing or null (the command then uses the active
|
|
/// photo), else that id. An `id` that isn't a whole number is an error, never `None`: falling back
|
|
/// would act on the active photo instead of the one the call meant (`{"id": "5"}`).
|
|
pub(crate) fn photo_id(p: &Value, cmd: &str) -> Result<Option<lightcraft_catalog::PhotoId>> {
|
|
match p.get("id") {
|
|
None | Some(Value::Null) => Ok(None),
|
|
Some(v) => v.as_u64().map(|n| Some(lightcraft_catalog::PhotoId(n))).ok_or_else(|| bad(cmd, "`id` must be a photo id (a whole number)")),
|
|
}
|
|
}
|
|
|
|
pub(crate) fn bad(cmd: &str, msg: impl Into<String>) -> EngineError {
|
|
EngineError::BadParams { cmd: cmd.into(), msg: msg.into() }
|
|
}
|
|
pub(crate) fn f64_req(p: &Value, key: &str, cmd: &str) -> Result<f64> {
|
|
p.get(key).and_then(Value::as_f64).ok_or_else(|| bad(cmd, format!("missing number `{key}`")))
|
|
}
|
|
/// A non-negative whole number that fits `usize`. Keep integer JSON exact; accept integral
|
|
/// floating-point values for compatibility, without truncating or saturating their conversion.
|
|
pub(crate) fn index_req(p: &Value, key: &str, cmd: &str) -> Result<usize> {
|
|
let invalid = || bad(cmd, format!("`{key}` must be a non-negative integer"));
|
|
if let Some(i) = p.get(key).and_then(Value::as_u64) {
|
|
return usize::try_from(i).map_err(|_| invalid());
|
|
}
|
|
let i = f64_req(p, key, cmd)?;
|
|
// The exclusive bound is exactly representable, unlike usize::MAX on 64-bit targets.
|
|
let upper_bound = 2.0_f64.powi(usize::BITS as i32);
|
|
if !(i.is_finite() && i >= 0.0 && i.fract() == 0.0 && i < upper_bound) {
|
|
return Err(invalid());
|
|
}
|
|
Ok(i as usize)
|
|
}
|
|
pub(crate) fn f64_or(p: &Value, key: &str, d: f64) -> f64 {
|
|
p.get(key).and_then(Value::as_f64).unwrap_or(d)
|
|
}
|
|
pub(crate) fn str_param<'a>(p: &'a Value, key: &str) -> Option<&'a str> {
|
|
p.get(key).and_then(Value::as_str)
|
|
}
|
|
pub(crate) fn bool_or(p: &Value, key: &str, d: bool) -> bool {
|
|
p.get(key).and_then(Value::as_bool).unwrap_or(d)
|
|
}
|
|
pub(crate) fn ok() -> Result<Value> {
|
|
Ok(Value::Null)
|
|
}
|
|
pub(crate) fn point(p: &Value, key: &str) -> Option<lightcraft_geom::Point> {
|
|
let a = p.get(key)?.as_array()?;
|
|
Some(lightcraft_geom::Point::new(a.first()?.as_f64()?, a.get(1)?.as_f64()?))
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use serde_json::json;
|
|
|
|
use super::index_req;
|
|
|
|
#[test]
|
|
fn command_indices_preserve_integer_precision_and_check_usize_bounds() {
|
|
for i in [0, 1, usize::MAX] {
|
|
assert_eq!(index_req(&json!({"index": i}), "index", "test").unwrap(), i);
|
|
}
|
|
#[cfg(target_pointer_width = "64")]
|
|
{
|
|
let i = 9_007_199_254_740_993usize;
|
|
assert_eq!(index_req(&json!({"index": i}), "index", "test").unwrap(), i, "integer JSON must not round through f64");
|
|
}
|
|
let upper_bound = 2.0_f64.powi(usize::BITS as i32);
|
|
assert!(index_req(&json!({"index": upper_bound}), "index", "test").is_err(), "2^usize::BITS must not saturate");
|
|
#[cfg(target_pointer_width = "32")]
|
|
{
|
|
assert!(index_req(&json!({"index": u64::from(u32::MAX) + 1}), "index", "test").is_err());
|
|
assert_eq!(index_req(&json!({"index": f64::from(u32::MAX)}), "index", "test").unwrap(), usize::MAX);
|
|
}
|
|
}
|
|
}
|