misc/localstorage
로컬 스토리지.
- 원본 misc/localstorage.js 를 옮긴 것이다. 문자열 키에 문자열 값을 영구 저장하는 정적 함수 묶음이다.
- 저장하는 곳: 웹(wasm32): 원본처럼 window.localStorage. (출처(origin)마다 따로, 키를 그대로 쓴다) 데스크탑: 앱 폴더의 localstorage.json 하나. (키 → 문자열 값의 JSON 객체, 쓸 때마다 바로 저장한다) 윈도우 %APPDATA%\{앱 이름}\localstorage.json 맥 $HOME/Library/Application Support/{앱 이름}/localstorage.json 리눅스 $XDG_DATA_HOME/{앱 이름}/localstorage.json (없으면 $HOME/.local/share/{앱 이름}/...) 환경 변수를 못 읽으면 임시 폴더(std::env::temp_dir) 아래에 둔다. 앱 이름은 기본으로 실행 파일 이름이다. set_application_name 이나 set_application_name_from_engine(EngineConfiguration.title)로 바꾼다. set_storage_directory 로 폴더를 직접 정할 수도 있다. (시험, 들고 다니는 게임)
- 원본과 다른 점: 숫자는 원본(JS number)처럼 f64 다. 글로 바꾸기는 원본 String(number) 그대로다. (가장 짧은 표기, 1e21 이상과 1e-7 이하는 1e+21 같은 지수, NaN, Infinity, -0 → "0") 읽기는 원본 Number(text) 그대로다. (JS 빈칸을 떼고, 빈 글은 0, 0x, 0o, 0b 표기, "1.", ".5", 지수, Infinity, 그 밖은 NaN) 데스크탑 저장은 스레드마다 따로 들고 있다가 파일에 쓴다. (엔진은 한 스레드에서 돈다)
- 저장소 갈아 끼우기: set_backend 에 LocalStorageBackend 를 넘기면 위 기본 저장소 대신 그것을 쓴다. (플랫폼 SDK 의 저장소 같은 것) 원본 setBackend 의 객체({ getItem, setItem, removeItem, getKeys, clear }) 자리가 트레이트다. 원본의 예외는 Err 로 알린다. 넘긴 저장소는
Rc<RefCell>에 담는다. get_backend 는 그 Rc 를 돌려주고, 부르는 쪽은 borrow / borrow_mut 로 빌려 쓴다. - 막혀도 죽지 않는다: 저장소가 없거나(웹의 막힌 localStorage) 쓰기가 실패하면(가득 참, 폴더를 못 만듦, 바꿔 낀 저장소의 Err) 이 실행이 살아 있는 동안 메모리에 대신 둔다. (is_memory_fallback, 다시 켜면 없다)
- 읽기(get_string, get_boolean, get_number, get_json)는 없는 키에 기본값을 써 넣지 않는다. (원본과 같다)
- 짝 없는 서로게이트: 원본 localStorage 는 JS 글(UTF-16)이라 짝 없는 서로게이트가 든 값(잘린 이모지 같은 것)과 그것을 \ud83d 꼴로 쓴 JSON 을 담는다. 러스트 String 은 그런 글을 담지 못해 러스트 쪽에는 대체 문자(U+FFFD)로 보이고, 읽은 값을 고치지 않고 다시 쓰면(set_item, set_string, set_json) 원래 UTF-16 단위 그대로 쓴다. (misc/storagetext.rs) 원래 단위가 필요하면 get_item_code_units, set_item_code_units 로 JS 글 그대로 읽고 쓴다. 키도 같다. 짝 없는 서로게이트로만 다른 두 키(원본에서 다른 키)는 러스트 글로는 같은 글로 보이지만 저장소 안에서는 따로 든다. get_keys_code_units 로 모든 키를 원래 단위로 받고, get_item_by_key_code_units, set_item_by_key_code_units, remove_item_by_key_code_units, contains_key_code_units 로 키와 값을 모두 원래 단위로 가려 부른다. (원본 localStorage 함수 그대로) 러스트 글 키는 그 글 그대로의 키가 있으면 그것, 없으면 그 글로 보이는 짝 없는 서로게이트 키의 첫째를 가리킨다. (get_keys 로 받은 키로 부를 수 있다) 웹은 브라우저 localStorage 에 JS 글 그대로 쓰고, 데스크탑 파일은 그런 값과 키를 원본 JSON.stringify 처럼 \udXXX 로 적는다. 바꿔 낀 저장소(LocalStorageBackend)는 러스트 글로 주고받아 그 저장소가 든 글 그대로다. (키도 보인 글로 준다)
Local storage.
- A port of the original misc/localstorage.js. A set of static functions that persistently store string values under string keys.
- Where it is stored: Web (wasm32): window.localStorage as in the original. (separate per origin, keys used as is) Desktop: a single localstorage.json in the app folder. (a JSON object of key → string value, saved immediately on every write) Windows %APPDATA%\{app name}\localstorage.json Mac $HOME/Library/Application Support/{app name}/localstorage.json Linux $XDG_DATA_HOME/{app name}/localstorage.json (if missing, $HOME/.local/share/{app name}/...) If the environment variables cannot be read, it goes under the temp folder (std::env::temp_dir). The app name defaults to the executable name. Change it with set_application_name or set_application_name_from_engine(EngineConfiguration.title). The folder can also be set directly with set_storage_directory. (tests, portable games)
- Differences from the original:
Numbers are f64 like the original (JS number). Conversion to text is exactly the original String(number). (shortest notation, exponents like 1e+21 for 1e21 and above and 1e-7 and below, NaN, Infinity, -0 → "0")
Reading is exactly the original Number(text). (trims JS whitespace, empty text is 0, 0x, 0o, 0b notation, "1.", ".5", exponents, Infinity, anything else is NaN)
Desktop storage is held per thread and then written to the file. (the engine runs on one thread)- Swapping the storage: passing a LocalStorageBackend to set_backend uses it instead of the default storage above. (such as a platform SDK's storage) The trait takes the place of the original setBackend object ({ getItem, setItem, removeItem, getKeys, clear }). Exceptions in the original are reported as Err. The passed storage is put in
Rc<RefCell>. get_backend returns that Rc, and the caller borrows it with borrow / borrow_mut. - Does not crash when blocked: if there is no storage (a blocked localStorage on the web) or writing fails (full, folder cannot be created, Err from the swapped storage), values are kept in memory instead for as long as this run lives. (is_memory_fallback, gone after a restart)
- Reads (get_string, get_boolean, get_number, get_json) do not write the default value for missing keys. (same as the original)
- Unpaired surrogates: the original localStorage holds JS strings (UTF-16), so it stores values containing unpaired surrogates (such as cut emoji) and JSON that writes them as \ud83d. Rust String cannot hold such text, so they appear as the replacement character (U+FFFD) on the Rust side, and writing a read value back unmodified (set_item, set_string, set_json) writes the original UTF-16 units as they were. (misc/storagetext.rs) If the original units are needed, get_item_code_units and set_item_code_units read and write the JS string as is. Keys are the same. Two keys that differ only by unpaired surrogates (different keys in the original) look like the same text as Rust strings but are stored separately in the storage. get_keys_code_units returns all keys in their original units, and get_item_by_key_code_units, set_item_by_key_code_units, remove_item_by_key_code_units and contains_key_code_units distinguish both key and value by original units. (exactly the original localStorage functions) A Rust string key points to the key with exactly that text if it exists, otherwise to the first unpaired surrogate key that appears as that text. (keys received from get_keys can be used) The web writes JS strings as is to the browser localStorage, and the desktop file writes such values and keys as \udXXX like the original JSON.stringify. A swapped storage (LocalStorageBackend) exchanges Rust strings, so values are exactly the text that storage holds. (keys are also given as the displayed text)
LocalStorageBackendtrait
바꿔 끼우는 저장소. (원본 setBackend 에 넘기는 객체)
- get_keys 와 clear 는 없어도 된다. get_keys 가 없으면 키 목록(get_keys, clear_by_prefix)은 메모리에 대신 둔 것만 보이고, clear 가 없으면 get_keys 의 키를 하나씩 지운다.
- 이 함수들 안에서 LocalStorage 를 다시 부르면 기본 저장소를 쓴다. (바꿔 낀 저장소는 부르는 동안 빌려 있다) get_backend 로 꺼낸 저장소를 빌린 채로 LocalStorage 를 불러도 기본 저장소를 쓴다.
Swappable storage backend. (the object passed to the original setBackend)
- get_keys and clear are optional. Without get_keys, the key list (get_keys, clear_by_prefix) only shows what was kept in memory instead, and without clear, the keys from get_keys are removed one by one.
- Calling LocalStorage again inside these functions uses the default storage. (the swapped backend is borrowed during the call) Calling LocalStorage while still borrowing the backend taken with get_backend also uses the default storage.
use std::cell::RefCell;
use std::collections::BTreeMap;
use std::rc::Rc;
use vanilla::{LocalStorage, LocalStorageBackend};
struct MemoryBackend {
item_map: Rc<RefCell<BTreeMap<String, String>>>,
}
impl LocalStorageBackend for MemoryBackend {
fn get_item(&self, key: &str) -> Result<Option<String>, String> {
Ok(self.item_map.borrow().get(key).cloned())
}
fn set_item(&mut self, key: &str, value: &str) -> Result<(), String> {
self.item_map.borrow_mut().insert(key.to_string(), value.to_string());
Ok(())
}
fn remove_item(&mut self, key: &str) -> Result<(), String> {
self.item_map.borrow_mut().remove(key);
Ok(())
}
fn get_keys(&self) -> Result<Vec<String>, String> {
Ok(self.item_map.borrow().keys().cloned().collect())
}
}
let item_map = Rc::new(RefCell::new(BTreeMap::new()));
LocalStorage::set_backend(Some(Box::new(MemoryBackend { item_map: item_map.clone() })));
LocalStorage::set_string("profile.name", "Player");
assert_eq!(item_map.borrow().get("profile.name").map(|value| value.as_str()), Some("Player"));
assert_eq!(LocalStorage::get_keys(), vec!["profile.name"]);
LocalStorage::set_backend(None);
assert!(LocalStorage::get_backend().is_none());값 읽기. (없으면 Ok(None))
Reads a value. (Ok(None) if missing)
- key&str
- 키.Key.
반환ReturnsResult<Option<String>, String> 저장된 글. 없으면 Ok(None), 못 읽으면 Err(까닭). (LocalStorage 는 Err 를 없는 것으로 읽는다)The stored text. Ok(None) if missing, Err(reason) if unreadable. (LocalStorage reads Err as missing)
값 쓰기.
Writes a value.
- key&str
- 키.Key.
- value&str
- 쓸 글.Text to write.
반환ReturnsResult<(), String> 썼으면 Ok(()). 못 쓰면 Err(까닭). (LocalStorage 는 그 값을 메모리에 대신 둔다)Ok(()) if written. Err(reason) if it could not write. (LocalStorage keeps that value in memory instead)
값 지우기.
Removes a value.
- key&str
- 지울 키.Key to remove.
반환ReturnsResult<(), String> 지웠으면 Ok(()). 못 지우면 Err(까닭). (LocalStorage 는 알리고 넘어간다)Ok(()) if removed. Err(reason) if it could not remove. (LocalStorage reports it and moves on)
모든 키. (기본은 빈 목록)
All keys. (an empty list by default)
반환ReturnsResult<Vec<String>, String> 모든 키. 못 읽으면 Err(까닭). (LocalStorage 는 빈 목록으로 친다)All keys. Err(reason) if unreadable. (LocalStorage treats it as an empty list)
전부 지우기. (기본은 get_keys 의 키를 하나씩 지운다)
Removes everything. (by default removes the keys from get_keys one by one)
반환ReturnsResult<(), String> 다 지웠으면 Ok(()). 못 지우면 Err(까닭). (LocalStorage 는 알리고 넘어간다)Ok(()) if everything was removed. Err(reason) if it could not remove. (LocalStorage reports it and moves on)
LocalStoragestruct
로컬 스토리지. (정적 함수 묶음)
Local storage. (a set of static functions)
use vanilla::LocalStorage;
let storage_directory_path = std::env::temp_dir().join(format!("vanillaLocalStorageExample-{}", std::process::id()));
LocalStorage::set_storage_directory(Some(storage_directory_path.clone()));
LocalStorage::set_number("example.bestScore", 1200.0);
LocalStorage::set_boolean("example.isMuted", true);
LocalStorage::set_json("example.settings", &serde_json::json!({ "volume": 0.8, "language": "en" }));
let best_score = LocalStorage::get_number("example.bestScore", 0.0);
let is_muted = LocalStorage::get_boolean("example.isMuted", false);
let settings = LocalStorage::get_json("example.settings", serde_json::json!({}));
assert_eq!(best_score, 1200.0);
assert!(is_muted);
assert_eq!(settings["volume"], 0.8);
assert!(LocalStorage::contains_key("example.bestScore"));
assert_eq!(LocalStorage::clear_by_prefix("example."), 3);
assert!(!LocalStorage::is_memory_fallback());
let _ = std::fs::remove_dir_all(&storage_directory_path);앱 이름 설정. (데스크탑 저장 폴더 이름. 웹은 출처마다 따로라 쓰지 않는다)
Sets the app name. (the desktop save folder name. Unused on the web, which is separate per origin)
- application_name&str
- 앱 이름. (폴더 이름에 못 쓰는 글자는 '_' 로 바꾸고, 비면 "vanilla")App name. (characters not allowed in folder names are replaced with '_', "vanilla" if empty)
엔진 설정의 창 제목을 앱 이름으로 쓴다. (EngineConfiguration.title)
Uses the window title from the engine configuration as the app name. (EngineConfiguration.title)
- engine&Engine
- 창 제목(EngineConfiguration.title)을 읽을 엔진.Engine to read the window title (EngineConfiguration.title) from.
저장 폴더 직접 설정. (None 이면 앱 이름으로 정한 기본 폴더. 웹은 쓰지 않는다)
Sets the save folder directly. (None uses the default folder derived from the app name. Unused on the web)
- storage_directory_pathOption<PathBuf>
- localstorage.json 을 둘 폴더. (None 이면 앱 이름으로 정한 기본 폴더)Folder to hold localstorage.json. (None means the default folder decided by the app name)
짝Counterpart: vanilla.js LocalStorage.setStorageDirectory
저장 파일 경로. (데스크탑만, 웹은 None)
Save file path. (desktop only, None on the web)
반환ReturnsOption<PathBuf> 저장 파일 경로. (데스크탑은 늘 Some, 웹은 None)Storage file path. (always Some on desktop, None on the web)
저장소 갈아 끼우기. (None 이면 기본 저장소로 돌아간다. 메모리에 대신 둔 값은 버린다)
Swaps the storage backend. (None returns to the default storage. Values kept in memory instead are discarded)
- backendOption<Box<dyn LocalStorageBackend>>
- 갈아 끼울 저장소. (None 이면 기본 저장소)Storage to swap in. (None means the default storage)
짝Counterpart: vanilla.js LocalStorage.setBackend
갈아 끼운 저장소 반환. (없으면 None, 빌릴 때는 borrow / borrow_mut)
Returns the swapped backend. (None if none, use borrow / borrow_mut to borrow it)
반환ReturnsOption<Rc<RefCell<Box<dyn LocalStorageBackend>>>> 갈아 끼운 저장소. 없으면 None.The swapped-in storage. None if none.
짝Counterpart: vanilla.js LocalStorage.getBackend
저장소를 못 써서 메모리에 대신 둔 적이 있는지.
Whether values were ever kept in memory because the storage could not be used.
반환Returnsbool 메모리로 대신한 적이 있으면 참. (set_backend 를 부르면 거짓으로 돌아간다)True if memory has ever been used instead. (returns to false when set_backend is called)
짝Counterpart: vanilla.js LocalStorage.isMemoryFallback
값 하나 읽기. (없거나 못 읽으면 None. 메모리에 대신 둔 값이 앞선다. 짝 없는 서로게이트는 대체 문자로 보인다)
Reads one value. (None if missing or unreadable. Values kept in memory instead take precedence. Unpaired surrogates appear as the replacement character)
- key&str
- 키.Key.
반환ReturnsOption<String> 저장된 글. 없거나 못 읽으면 None.The stored text. None if missing or unreadable.
짝Counterpart: vanilla.js LocalStorage.getItem
값 하나를 원래 UTF-16 단위로 읽기. (원본 JS 글 그대로, 짝 없는 서로게이트도 담는다)
Reads one value as the original UTF-16 units. (the original JS string as is, unpaired surrogates included)
- key&str
- 키.Key.
반환ReturnsOption<Vec<u16>> 저장된 글의 UTF-16 단위. 없거나 못 읽으면 None.UTF-16 units of the stored text. None if missing or unreadable.
값 하나 쓰기. (저장소에 썼으면 true, 못 써서 메모리에 대신 뒀으면 false)
- 이 키에서 읽은 짝 없는 서로게이트가 든 값을 고치지 않고 다시 쓰면 원래 단위로 쓴다.
Writes one value. (true if written to the storage, false if kept in memory instead because it could not be written)
- Writing back an unmodified value containing unpaired surrogates read from this key writes the original units.
- key&str
- 키.Key.
- value&str
- 쓸 글.Text to write.
반환Returnsbool 저장소에 썼으면 참. 메모리에 대신 뒀으면 거짓.True if written to the storage. False if kept in memory instead.
짝Counterpart: vanilla.js LocalStorage.setItem
값 하나를 UTF-16 단위로 쓰기. (원본 JS 글 그대로, 짝 없는 서로게이트도 그대로 쓴다)
Writes one value as UTF-16 units. (the original JS string as is, unpaired surrogates written as they are)
- key&str
- 키.Key.
- code_units&[u16]
- 쓸 글의 UTF-16 단위.UTF-16 units of the text to write.
반환Returnsbool 저장소에 썼으면 참. 메모리에 대신 뒀으면 거짓.True if written to the storage. False if kept in memory instead.
값 하나 지우기. (메모리에 대신 둔 값도 지운다)
Removes one value. (also removes the value kept in memory instead)
- key&str
- 지울 키.Key to remove.
짝Counterpart: vanilla.js LocalStorage.removeItem
키와 값을 모두 UTF-16 단위로 읽기. (원본 localStorage.getItem 그대로, 짝 없는 서로게이트로만 다른 두 키도 가린다)
Reads with both key and value in UTF-16 units. (exactly the original localStorage.getItem, also distinguishes two keys that differ only by unpaired surrogates)
- key_code_units&[u16]
- 키의 UTF-16 단위.UTF-16 units of the key.
반환ReturnsOption<Vec<u16>> 저장된 글의 UTF-16 단위. 없거나 못 읽으면 None.UTF-16 units of the stored text. None if missing or unreadable.
pub fn set_item_by_key_code_units(key_code_units: &[u16], value_code_units: &[u16]) -> bool#키와 값을 모두 UTF-16 단위로 쓰기. (원본 localStorage.setItem 그대로, 저장소에 썼으면 true)
Writes with both key and value in UTF-16 units. (exactly the original localStorage.setItem, true if written to the storage)
- key_code_units&[u16]
- 키의 UTF-16 단위.UTF-16 units of the key.
- value_code_units&[u16]
- 쓸 글의 UTF-16 단위.UTF-16 units of the text to write.
반환Returnsbool 저장소에 썼으면 참. 메모리에 대신 뒀으면 거짓.True if written to the storage. False if kept in memory instead.
UTF-16 단위 키로 지우기. (원본 localStorage.removeItem 그대로)
Removes by a UTF-16 unit key. (exactly the original localStorage.removeItem)
- key_code_units&[u16]
- 지울 키의 UTF-16 단위.UTF-16 units of the key to remove.
UTF-16 단위 키가 있는지.
Whether a UTF-16 unit key exists.
- key_code_units&[u16]
- 찾을 키의 UTF-16 단위.UTF-16 units of the key to look for.
반환Returnsbool 값이 있으면 참.True if a value exists.
문자열 값 설정.
Sets a string value.
- key&str
- 키.Key.
- string_value&str
- 쓸 글.Text to write.
짝Counterpart: vanilla.js LocalStorage.setString
논리 값 설정. ("true" / "false" 로 저장한다)
Sets a boolean value. (stored as "true" / "false")
- key&str
- 키.Key.
- boolean_valuebool
- 쓸 값. ("true" 나 "false" 글로 쓴다)Value to write. (written as the text "true" or "false")
짝Counterpart: vanilla.js LocalStorage.setBoolean
숫자 값 설정. (원본 String(number) 꼴로 저장한다)
Sets a number value. (stored in the original String(number) form)
- key&str
- 키.Key.
- number_valuef64
- 쓸 값. (원본 String(number) 꼴의 글로 바꿔 쓴다)Value to write. (converted to text in the original String(number) form)
짝Counterpart: vanilla.js LocalStorage.setNumber
문자열 값 반환. (없으면 기본값. 저장소에는 쓰지 않는다)
Returns a string value. (the default value if missing. Not written to the storage)
- key&str
- 키.Key.
- default_string_value&str
- 없을 때 돌려줄 값.Value returned when missing.
반환ReturnsString 저장된 글. 없으면 기본값.The stored text. The default value if missing.
짝Counterpart: vanilla.js LocalStorage.getString
논리 값 반환. (없거나 빈 글이면 기본값, 저장소에는 쓰지 않는다. "true" 만 참)
Returns a boolean value. (the default value if missing or an empty string, not written to the storage. Only "true" is true)
- key&str
- 키.Key.
- default_boolean_valuebool
- 없거나 빈 글일 때 돌려줄 값.Value returned when missing or empty.
반환Returnsbool 저장된 글이 "true" 면 참. 없거나 빈 글이면 기본값.True if the stored text is "true". The default value if missing or empty.
짝Counterpart: vanilla.js LocalStorage.getBoolean
숫자 값 반환. (없거나 빈 글이면 기본값, 저장소에는 쓰지 않는다. 숫자가 아니면 NaN, 원본 Number(text))
Returns a number value. (the default value if missing or an empty string, not written to the storage. NaN if not a number, original Number(text))
- key&str
- 키.Key.
- default_number_valuef64
- 없거나 빈 글일 때 돌려줄 값.Value returned when missing or empty.
반환Returnsf64 저장된 글을 원본 Number(text) 처럼 바꾼 값. (없거나 빈 글이면 기본값, 숫자가 아니면 NaN)The stored text converted like the original Number(text). (the default value if missing or empty, NaN if not a number)
짝Counterpart: vanilla.js LocalStorage.getNumber
접두사로 시작하는 키 한꺼번에 지우기. (게임 네임스페이스의 저장을 통째로 지울 때, 지운 키 수)
- 보인 글로 견준다. 짝 없는 서로게이트로만 다른 키도 따로 센다.
Removes all keys starting with a prefix at once. (for wiping a game namespace's saves entirely, the number of removed keys)
- Compares by the displayed text. Keys that differ only by unpaired surrogates are counted separately.
- prefix&str
- 지울 키의 접두사. (빈 글이면 아무것도 지우지 않는다)Prefix of the keys to remove. (removes nothing if empty)
반환Returnsusize 지운 키 수.Number of removed keys.
짝Counterpart: vanilla.js LocalStorage.clearByPrefix
키가 있는지.
Whether the key exists.
- key&str
- 찾을 키.Key to look for.
반환Returnsbool 값이 있으면 참.True if a value exists.
짝Counterpart: vanilla.js LocalStorage.containsKey
모든 키 반환. (정렬해서, 메모리에 대신 둔 키도 넣는다)
- 짝 없는 서로게이트가 든 키는 대체 문자로 보인다. 보인 글이 같은 키는 하나만 나오니, 모두 가려 보려면 get_keys_code_units.
Returns all keys. (sorted, includes keys kept in memory instead)
- Keys containing unpaired surrogates appear with the replacement character. Keys with the same displayed text appear only once, so use get_keys_code_units to tell them all apart.
반환ReturnsVec<String> 저장소와 메모리의 키를 합쳐 정렬한 목록.Sorted list of the keys in the storage and in memory combined.
짝Counterpart: vanilla.js LocalStorage.getKeys
모든 키를 UTF-16 단위로 반환. (원본 localStorage.key(i) 의 글 그대로, 정렬해서)
Returns all keys in UTF-16 units. (exactly the strings of the original localStorage.key(i), sorted)
반환ReturnsVec<Vec<u16>> 모든 키의 UTF-16 단위 목록. (저장소와 메모리의 키를 합쳐 정렬한다)List of all keys in UTF-16 units. (the keys in the storage and in memory combined and sorted)
JSON 값 반환. (없거나 풀 수 없으면 기본값, 저장소에는 쓰지 않는다)
- 짝 없는 서로게이트가 든 글(원본 JSON.stringify 의 \ud83d 같은 것)은 대체 문자로 읽고, 그 자리를 남겨 set_json 이 원래대로 쓴다.
Returns a JSON value. (the default value if missing or unparsable, not written to the storage)
- Strings containing unpaired surrogates (like \ud83d from the original JSON.stringify) are read with the replacement character, and their positions are kept so set_json writes them back as they were.
- key&str
- 키.Key.
- default_valueserde_json::Value
- 없거나 빈 글이거나 풀 수 없을 때 돌려줄 값.Value returned when missing, empty or unparsable.
반환Returnsserde_json::Value 풀어 낸 값. 없거나 풀 수 없으면 기본값.The parsed value. The default value if missing or unparsable.
짝Counterpart: vanilla.js LocalStorage.getJson
JSON 값 설정. (JSON 글로 바꿔 쓴다. 저장소에 썼으면 true)
- get_json 으로 읽은 짝 없는 서로게이트가 든 글을 고치지 않았으면 원본 JSON.stringify 처럼 \udXXX 로 쓴다.
Sets a JSON value. (written as JSON text. true if written to the storage)
- If strings containing unpaired surrogates read with get_json were not modified, writes them as \udXXX like the original JSON.stringify.
- key&str
- 키.Key.
- value&serde_json::Value
- JSON 으로 바꿔 쓸 값.Value to write as JSON.
반환Returnsbool 저장소에 썼으면 참. (메모리에 대신 뒀으면 거짓)True if written to the storage. (false if kept in memory instead)
짝Counterpart: vanilla.js LocalStorage.setJson