Skip to repository content

tenant.openagents/omega

No repository description is available.

OpenAgents Git authority 2026-07-28T04:59:07.431Z Public web read
NIP-34 coordinate30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omega
MaintainersHidden in public view
References2 branches · 1 tag
Read-only clonegit clone https://openagents.com/git/tenant.openagents/omega.git
Browse files

owned_string_into_shared.rs

69 lines · 2.2 KB · rust
1// Tests for the `owned_string_into_shared` lint.
2
3#![allow(unused)]
4
5use std::borrow::Cow;
6use std::rc::Rc;
7use std::sync::Arc;
8
9fn main() {
10    // --- Should warn ---
11
12    // String::from(<literal>).into() into Arc<str>.
13    let _a: Arc<str> = String::from("hello").into();
14
15    // String::from(<literal>).into() into Rc<str>.
16    let _b: Rc<str> = String::from("world").into();
17
18    // String::from(<literal>).into() into Cow<'_, str>.
19    let _c: Cow<'_, str> = String::from("borrowed-or-owned").into();
20
21    // <literal>.to_string().into() into Arc<str>.
22    let _d: Arc<str> = "via-to-string".to_string().into();
23
24    // <literal>.to_owned().into() into Arc<str>.
25    let _e: Arc<str> = "via-to-owned".to_owned().into();
26
27    // <literal>.to_string().into() into Rc<str>.
28    let _f: Rc<str> = "rc-via-to-string".to_string().into();
29
30    // <literal>.to_owned().into() into Cow<'_, str>.
31    let _g: Cow<'_, str> = "cow-via-to-owned".to_owned().into();
32
33    // Long literal still flagged the same way.
34    let _h: Arc<str> =
35        String::from("this literal is definitely longer than twenty three bytes").into();
36
37    // --- Should NOT warn ---
38
39    // Direct construction from the literal — already optimal.
40    let _ok1: Arc<str> = Arc::from("hello");
41    let _ok2: Rc<str> = Rc::from("world");
42    let _ok3: Cow<'_, str> = Cow::Borrowed("borrowed");
43
44    // Producing a plain `String` (not a refcounted destination).
45    let _ok4: String = String::from("not refcounted");
46    let _ok5: String = "x".to_string();
47    let _ok6: String = "x".to_owned();
48
49    // `.into()` from a non-literal `String` — the allocation is unavoidable.
50    let dynamic: String = make_string();
51    let _ok7: Arc<str> = dynamic.into();
52
53    // `.into()` from a `&str` directly (no owned `String` in between).
54    let _ok8: Arc<str> = "direct".into();
55
56    // `.into()` whose destination is not one of the targeted types.
57    let _ok9: Box<str> = String::from("box-str").into();
58
59    // `String::new()` is not built from a literal.
60    let _ok10: Arc<str> = String::new().into();
61
62    // Method call that is not `into`.
63    let _ok11: String = String::from("foo").clone();
64}
65
66fn make_string() -> String {
67    String::from("dynamic")
68}
69
Served at tenant.openagents/omega Member data and write actions are omitted.