update examples and add documentation

This commit is contained in:
zekro committed 2026-07-17 11:30:08 +02:00
1 parent 9e4e019660
commit e42d897d41
7 files changed
+34 -21

No files matched your search

+1 -1
View File
@@ -10,7 +10,7 @@ struct CredentialManager {
impl CredentialManager {
pub fn new() -> CredentialManager {
CredentialManager {
locked: false,
locked: true,
entries: HashMap::new(),
}
}
+5 -5
View File
@@ -41,9 +41,9 @@ impl UnlockedCredentialManager {
}
fn main() {
let pw = LockedCredentialManager::new();
let mut pw = pw.unlock("pssst");
pw.set("foo", "bar");
let val = pw.get("foo");
pw.lock();
let pw_locked = LockedCredentialManager::new();
let mut pw_unlocked = pw_locked.unlock("pssst");
pw_unlocked.set("foo", "bar");
let val = pw_unlocked.get("foo");
let pw_locked = pw_unlocked.lock();
}
+6 -6
View File
@@ -11,7 +11,7 @@ struct CredentialManager<State = Locked> {
}
impl CredentialManager {
pub fn new() -> CredentialManager<Locked> {
pub fn new() -> CredentialManager {
CredentialManager {
entries: HashMap::new(),
state: std::marker::PhantomData,
@@ -46,9 +46,9 @@ impl CredentialManager<Unlocked> {
}
fn main() {
let pw = CredentialManager::new();
let mut pw = pw.unlock("pssst");
pw.set("foo", "bar");
let val = pw.get("foo");
pw.lock();
let pw_locked = CredentialManager::new();
let mut pw_unlocked = pw_locked.unlock("pssst");
pw_unlocked.set("foo", "bar");
let val = pw_unlocked.get("foo");
let pw_locked = pw_unlocked.lock();
}
+5 -7
View File
@@ -35,11 +35,9 @@ func (m UnlockedCredentialManager) Lock() LockedCredentialManager {
}
func main() {
pw := NewCredentialManager()
unlocked := pw.Unlock("pssst")
unlocked.Set("foo", "bar")
_, _ = unlocked.Get("foo")
unlocked.Lock()
pwLocked := NewCredentialManager()
pwUnlocked := pwLocked.Unlock("pssst")
pwUnlocked.Set("foo", "bar")
_, _ = pwUnlocked.Get("foo")
pwUnlocked.Lock()
}
+8
View File
@@ -52,3 +52,11 @@ func (t *credentialManager) Get(key string) (string, error) {
}
panic("todo")
}
func main() {
pwLocked := NewCredentialManager()
pwUnlocked, _ := pwLocked.Unlock("pssst")
pwUnlocked.Set("foo", "bar")
_, _ = pwUnlocked.Get("foo")
pwUnlocked.Lock()
}
+2 -2
View File
@@ -22,7 +22,7 @@ type OpArgsMapping = {
};
class WebSocketClient {
public op<TOp extends OpCode, TArgs extends OpArgsMapping[TOp]>(
public send<TOp extends OpCode, TArgs extends OpArgsMapping[TOp]>(
op: TOp,
args: TArgs,
) {
@@ -32,5 +32,5 @@ class WebSocketClient {
function main_ws() {
const client = new WebSocketClient();
client.op(OpCode.PING, {});
client.send(OpCode.PING, {});
}
+7
View File
@@ -1,3 +1,9 @@
// This recursively matches path segments and parameters in segments which
// are surrounded by curly braces (i.e. `{foo}`) in these segments.
// The results are joined to a superset of objects with their params
// via the `&`.
// In example, the path /{foo}/{bar} results in the type
// `{ foo: string } & { bar: string }`
type ParseUrlParamsRaw<Url> = Url extends `${infer Start}/${infer Rest}`
? ParseUrlParamsRaw<Start> & ParseUrlParamsRaw<Rest>
: Url extends `{${infer Param}}`
@@ -20,4 +26,5 @@ function navigate<P extends string>(path: P, params: ParseUrlParams<P>) {
function main() {
navigate("/hello", {});
navigate("/hello/{name}", { name: "foo" });
navigate("/book/{author}/{id}", { author: "foo", id: "bar" });
}