vanilladocs
vanillapunch.com
API / base/identifier

base/identifier

식별자. (원본 base/identifier.js)

  • create_instance_id: 원본 Object 의 instance_id 자리. (스레드와 상관없이 겹치지 않는 번호)
  • Identifier: 원본처럼 처음 번호와 늘릴 수로 차례 번호를 낸다. reset 은 처음 번호로 되돌린다. (원본 reset 이 자기 값을 자기에 다시 넣어 아무것도 하지 않던 버그는 원본에서도 고쳤다)
  • 원본 Enum(begin, auto, readonly)은 자바스크립트 객체로 열거형을 흉내 낸 것이라 옮기지 않는다. 러스트는 enum 을 쓴다.
  • create_guid: 원본 base/reflection.js 의 createGUID. (앞 12 자리는 밀리초 시각, 나머지는 난수인 UUID 꼴 글. 원본 reflection.js 의 나머지는 자바스크립트 객체 반사라 옮기지 않는다)

Identifiers. (the original base/identifier.js)

  • create_instance_id: in place of the original Object's instance_id. (numbers that never overlap regardless of thread)
  • Identifier: like the original, issues sequence numbers from a starting number and an increment. reset goes back to the starting number. (the bug where the original reset put its own value back into itself and did nothing was also fixed in the original)
  • The original Enum(begin, auto, readonly) imitates enums with JavaScript objects, so it is not ported. Rust uses enum.
  • create_guid: createGUID of the original base/reflection.js. (a UUID-form string whose first 12 digits are the millisecond time and the rest random. The rest of the original reflection.js is JavaScript object reflection, so it is not ported)

Identifierstruct traits Clone, Debug, Default

짝Counterpart: vanilla.js Identifier소스source

차례 번호 발급기. (원본 Identifier)

Sequence number issuer. (the original Identifier)

예제Example100 에서 5 씩 늘리고 되돌리기Increase by 5 from 100 and reset
use vanilla::Identifier;

let mut identifier = Identifier::new(100, 5);
assert_eq!(identifier.auto(0), 105);
assert_eq!(identifier.auto(0), 110);
assert_eq!(identifier.auto(1), 111);
identifier.reset();
assert_eq!(identifier.auto(0), 105);
생성자constructorpub fn new(initial_serial_number: i64, initial_increase_number: i64) -> Identifier#0.4.0 부터since 0.4.0소스source

생성. (처음 번호, 한 번에 늘릴 수, 원본 기본값은 0 과 1)

Constructor. (starting number, amount to increase at a time; the original defaults are 0 and 1)

initial_serial_numberi64
처음 번호. (reset 이 되돌리는 번호, 첫 auto 는 여기에 늘린 값을 돌려준다)Starting number. (the number reset goes back to; the first auto returns this plus the increment)
initial_increase_numberi64
auto(0) 이 한 번에 늘릴 수.Amount auto(0) increases at a time.

반환ReturnsIdentifier 처음 번호에 선 발급기.An issuer at its starting number.

짝Counterpart: vanilla.js Identifier.constructor

메서드methodpub fn reset(&mut self)#0.4.0 부터since 0.4.0소스source

처음 번호로 되돌리기.

Resets to the starting number.

짝Counterpart: vanilla.js Identifier.reset

메서드methodpub fn auto(&mut self, increase_number: i64) -> i64#0.4.0 부터since 0.4.0소스source

다음 번호. (increase_number 가 0 이 아니면 그만큼, 0 이면 만들 때 정한 수만큼 늘린 뒤 돌려준다)

Next number. (increases by increase_number if it is not 0, or by the amount set at creation if 0, then returns it)

increase_numberi64
이번에 늘릴 수. (0 이면 만들 때 정한 수)Amount to increase this time. (the amount set at creation if 0)

반환Returnsi64 늘린 뒤의 번호.The number after increasing.

짝Counterpart: vanilla.js Identifier.auto

함수Functions

함수functionpub fn create_instance_id() -> u64#0.3.2 부터since 0.3.2소스source

새 인스턴스 식별자. (1 부터, 겹치지 않음)

New instance identifier. (from 1, never overlapping)

반환Returnsu64 프로세스 안에서 부를 때마다 1 씩 오르는 번호. (첫 번호 1, 스레드끼리도 겹치지 않는다)A number that rises by 1 each time it is called within the process. (first number 1, never overlaps across threads either)

함수functionpub fn create_guid() -> String#0.4.0 부터since 0.4.0소스source

고유식별자 생성. (원본 createGUID, "0192a3f2-b1c4-4d8e-8f1a-0e5d4c3b2a19")

  • 48 비트 밀리초 시각을 16 진수 12 자리로 앞에 두고, 판 4 와 변형 8 ~ b 자리 말고는 난수다. (74 비트)

Generates a unique identifier. (the original createGUID, "0192a3f2-b1c4-4d8e-8f1a-0e5d4c3b2a19")

  • Puts the 48-bit millisecond time first as 12 hex digits; apart from the version 4 and variant 8 ~ b digits, the rest is random. (74 bits)

반환ReturnsString 8-4-4-4-12 꼴의 소문자 16 진수 글. (36 글자, 시계가 유닉스 기준 시각(1970 년)보다 앞이면 시각 자리는 0)Lowercase hex string in 8-4-4-4-12 form. (36 characters; the time digits are 0 if the clock is before the Unix epoch (1970))

짝Counterpart: vanilla.js createGUID

예제ExampleUUID 꼴 확인Check the UUID form
use vanilla::create_guid;

let guid = create_guid();
assert_eq!(guid.len(), 36);
assert_eq!(guid.split('-').map(|part| part.len()).collect::<Vec<usize>>(), vec![8, 4, 4, 4, 12]);
assert_ne!(create_guid(), create_guid());