Skip to content

Commit 0bce754

Browse files
authored
Merge pull request #134 from flub/as_str
Rename to_str() -> as_str() to match stdlib naming convention
2 parents a32a275 + 855c784 commit 0bce754

19 files changed

+84
-84
lines changed

examples/repl/cmdline.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,14 @@ unsafe fn poke_spec(context: &Context, spec: *const libc::c_char) -> libc::c_int
172172
current_block = 1622411330066726685;
173173
} else {
174174
/* import a directory */
175-
let dir_name = std::path::Path::new(to_str(real_spec));
175+
let dir_name = std::path::Path::new(as_str(real_spec));
176176
let dir = std::fs::read_dir(dir_name);
177177
if dir.is_err() {
178178
error!(
179179
context,
180180
0,
181181
"Import: Cannot open directory \"{}\".",
182-
to_str(real_spec),
182+
as_str(real_spec),
183183
);
184184
current_block = 8522321847195001863;
185185
} else {
@@ -192,7 +192,7 @@ unsafe fn poke_spec(context: &Context, spec: *const libc::c_char) -> libc::c_int
192192
let name_f = entry.file_name();
193193
let name = name_f.to_string_lossy();
194194
if name.ends_with(".eml") {
195-
let path_plus_name = format!("{}/{}", to_str(real_spec), name);
195+
let path_plus_name = format!("{}/{}", as_str(real_spec), name);
196196
info!(context, 0, "Import: {}", path_plus_name);
197197
let path_plus_name_c = to_cstring(path_plus_name);
198198

@@ -212,7 +212,7 @@ unsafe fn poke_spec(context: &Context, spec: *const libc::c_char) -> libc::c_int
212212
0,
213213
"Import: {} items read from \"{}\".",
214214
read_cnt,
215-
to_str(real_spec)
215+
as_str(real_spec)
216216
);
217217
if read_cnt > 0 {
218218
(context.cb)(context, Event::MSGS_CHANGED, 0 as uintptr_t, 0 as uintptr_t);
@@ -253,9 +253,9 @@ unsafe fn log_msg(context: &Context, prefix: impl AsRef<str>, msg: *mut dc_msg_t
253253
""
254254
},
255255
if dc_msg_has_location(msg) { "📍" } else { "" },
256-
to_str(contact_name),
256+
as_str(contact_name),
257257
contact_id,
258-
to_str(msgtext),
258+
as_str(msgtext),
259259
if 0 != dc_msg_is_starred(msg) {
260260
"★"
261261
} else {
@@ -276,7 +276,7 @@ unsafe fn log_msg(context: &Context, prefix: impl AsRef<str>, msg: *mut dc_msg_t
276276
""
277277
},
278278
statestr,
279-
to_str(temp2),
279+
as_str(temp2),
280280
);
281281
free(msgtext as *mut libc::c_void);
282282
free(temp2 as *mut libc::c_void);
@@ -345,19 +345,19 @@ unsafe fn log_contactlist(context: &Context, contacts: *mut dc_array_t) {
345345
line = format!(
346346
"{}{} <{}>",
347347
if !name.is_null() && 0 != *name.offset(0isize) as libc::c_int {
348-
to_str(name)
348+
as_str(name)
349349
} else {
350350
"<name unset>"
351351
},
352352
verified_str,
353353
if !addr.is_null() && 0 != *addr.offset(0isize) as libc::c_int {
354-
to_str(addr)
354+
as_str(addr)
355355
} else {
356356
"addr unset"
357357
}
358358
);
359359
let peerstate =
360-
Peerstate::from_addr(context, &context.sql.clone().read().unwrap(), to_str(addr));
360+
Peerstate::from_addr(context, &context.sql.clone().read().unwrap(), as_str(addr));
361361
if peerstate.is_some() && contact_id != 1 as libc::c_uint {
362362
line2 = format!(
363363
", prefer-encrypt={}",
@@ -502,7 +502,7 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
502502
if 0 == S_IS_AUTH {
503503
let is_pw =
504504
dc_get_config(context, b"mail_pw\x00" as *const u8 as *const libc::c_char);
505-
if arg1 == to_str(is_pw) {
505+
if arg1 == as_str(is_pw) {
506506
S_IS_AUTH = 1;
507507
} else {
508508
println!("Bad password.");
@@ -527,7 +527,7 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
527527
if !setup_code.is_null() {
528528
println!(
529529
"Setup code for the transferred setup message: {}",
530-
to_str(setup_code),
530+
as_str(setup_code),
531531
);
532532
free(setup_code as *mut libc::c_void);
533533
} else {
@@ -543,7 +543,7 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
543543
println!(
544544
"The setup code for setup message Msg#{} starts with: {}",
545545
msg_id,
546-
to_str(setupcodebegin),
546+
as_str(setupcodebegin),
547547
);
548548
free(setupcodebegin as *mut libc::c_void);
549549
} else {
@@ -597,8 +597,8 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
597597
{
598598
println!(
599599
"Setup message written to: {}\nSetup code: {}",
600-
to_str(file_name),
601-
to_str(setup_code),
600+
as_str(file_name),
601+
as_str(setup_code),
602602
)
603603
} else {
604604
bail!("");
@@ -666,8 +666,8 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
666666
"{}#{}: {} [{}] [{} fresh]",
667667
chat_prefix(chat),
668668
dc_chat_get_id(chat) as libc::c_int,
669-
to_str(temp_name),
670-
to_str(temp_subtitle),
669+
as_str(temp_name),
670+
as_str(temp_subtitle),
671671
dc_get_fresh_msg_cnt(context, dc_chat_get_id(chat)) as libc::c_int,
672672
);
673673
free(temp_subtitle as *mut libc::c_void);
@@ -695,7 +695,7 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
695695
if !text1.is_null() { ": " } else { "" },
696696
to_string(text2),
697697
statestr,
698-
to_str(timestr),
698+
as_str(timestr),
699699
if 0 != dc_chat_is_sending_locations(chat) {
700700
"📍"
701701
} else {
@@ -746,8 +746,8 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
746746
"{}#{}: {} [{}]{}",
747747
chat_prefix(sel_chat),
748748
dc_chat_get_id(sel_chat),
749-
to_str(temp_name),
750-
to_str(temp2),
749+
as_str(temp_name),
750+
as_str(temp2),
751751
if 0 != dc_chat_is_sending_locations(sel_chat) {
752752
"📍"
753753
} else {
@@ -902,15 +902,15 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
902902
0,
903903
"Loc#{}: {}: lat={} lng={} acc={} Chat#{} Contact#{} Msg#{} {}",
904904
dc_array_get_id(loc, j as size_t),
905-
to_str(timestr_0),
905+
as_str(timestr_0),
906906
dc_array_get_latitude(loc, j as size_t),
907907
dc_array_get_longitude(loc, j as size_t),
908908
dc_array_get_accuracy(loc, j as size_t),
909909
dc_array_get_chat_id(loc, j as size_t),
910910
dc_array_get_contact_id(loc, j as size_t),
911911
dc_array_get_msg_id(loc, j as size_t),
912912
if !marker.is_null() {
913-
to_str(marker)
913+
as_str(marker)
914914
} else {
915915
"-"
916916
},
@@ -1046,7 +1046,7 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
10461046
ensure!(!arg1.is_empty(), "Argument <msg-id> missing.");
10471047
let id = arg1.parse().unwrap();
10481048
let res = dc_get_msg_info(context, id);
1049-
println!("{}", to_str(res));
1049+
println!("{}", as_str(res));
10501050
}
10511051
"listfresh" => {
10521052
let msglist = dc_get_fresh_msgs(context);
@@ -1132,12 +1132,12 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
11321132
let contact = dc_get_contact(context, contact_id);
11331133
let name_n_addr = dc_contact_get_name_n_addr(contact);
11341134

1135-
let mut res = format!("Contact info for: {}:\n\n", to_str(name_n_addr),);
1135+
let mut res = format!("Contact info for: {}:\n\n", as_str(name_n_addr),);
11361136
free(name_n_addr as *mut libc::c_void);
11371137
dc_contact_unref(contact);
11381138

11391139
let encrinfo = dc_get_contact_encrinfo(context, contact_id);
1140-
res += to_str(encrinfo);
1140+
res += as_str(encrinfo);
11411141
free(encrinfo as *mut libc::c_void);
11421142

11431143
let chatlist = dc_get_chatlist(context, 0, 0 as *const libc::c_char, contact_id);

examples/repl/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ unsafe fn handle_cmd(line: &str, ctx: Arc<RwLock<Context>>) -> Result<ExitResult
521521
} else {
522522
let oauth2_url = dc_get_oauth2_url(
523523
&ctx.read().unwrap(),
524-
to_str(addr),
524+
as_str(addr),
525525
"chat.delta:/com.b44t.messenger",
526526
);
527527
if oauth2_url.is_none() {

src/context.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -754,8 +754,8 @@ pub unsafe fn dc_get_info(context: &Context) -> *mut libc::c_char {
754754
public_key_count={}\n\
755755
fingerprint={}\n\
756756
level=awesome\n",
757-
to_str(DC_VERSION_STR as *const u8 as *const _),
758-
to_str(libsqlite3_sys::SQLITE_VERSION as *const u8 as *const libc::c_char),
757+
as_str(DC_VERSION_STR as *const u8 as *const _),
758+
as_str(libsqlite3_sys::SQLITE_VERSION as *const u8 as *const libc::c_char),
759759
sqlite3_threadsafe(),
760760
// arch
761761
(::std::mem::size_of::<*mut libc::c_void>()).wrapping_mul(8),
@@ -764,31 +764,31 @@ pub unsafe fn dc_get_info(context: &Context) -> *mut libc::c_char {
764764
deaddrop_msgs,
765765
contacts,
766766
if context.has_dbfile() {
767-
to_str(context.get_dbfile())
767+
as_str(context.get_dbfile())
768768
} else {
769769
unset
770770
},
771771
dbversion,
772772
if context.has_blobdir() {
773-
to_str(context.get_blobdir())
773+
as_str(context.get_blobdir())
774774
} else {
775775
unset
776776
},
777777
if !displayname.is_null() {
778-
to_str(displayname)
778+
as_str(displayname)
779779
} else {
780780
unset
781781
},
782782
is_configured,
783-
to_str(l_readable_str),
784-
to_str(l2_readable_str),
783+
as_str(l_readable_str),
784+
as_str(l2_readable_str),
785785
inbox_watch,
786786
sentbox_watch,
787787
mvbox_watch,
788788
mvbox_move,
789789
folders_configured,
790-
to_str(configured_sentbox_folder),
791-
to_str(configured_mvbox_folder),
790+
as_str(configured_sentbox_folder),
791+
as_str(configured_mvbox_folder),
792792
mdns_enabled,
793793
e2ee_enabled,
794794
prv_key_cnt,

src/dc_array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ pub unsafe fn dc_array_get_string(
360360
}
361361
let cnt = (*array).count as usize;
362362
let slice = std::slice::from_raw_parts((*array).array, cnt);
363-
let sep = to_str(sep);
363+
let sep = as_str(sep);
364364

365365
let res = slice
366366
.iter()

src/dc_configure.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &Context, _job: *mut dc_j
207207
);
208208
let oauth2_addr = dc_get_oauth2_addr(
209209
context,
210-
to_str((*param).addr),
211-
to_str((*param).mail_pw),
210+
as_str((*param).addr),
211+
as_str((*param).mail_pw),
212212
);
213213
if oauth2_addr.is_some() {
214214
free((*param).addr as *mut libc::c_void);
@@ -1432,7 +1432,7 @@ unsafe fn moz_autoconfigure_text_cb(
14321432
(*(*moz_ac).out).send_server = val;
14331433
val = 0 as *mut libc::c_char
14341434
}
1435-
11 => (*(*moz_ac).out).send_port = to_str(val).parse().unwrap_or_default(),
1435+
11 => (*(*moz_ac).out).send_port = as_str(val).parse().unwrap_or_default(),
14361436
12 => {
14371437
free((*(*moz_ac).out).send_user as *mut libc::c_void);
14381438
(*(*moz_ac).out).send_user = val;
@@ -1526,7 +1526,7 @@ fn read_autoconf_file(context: &Context, url: *const libc::c_char) -> *mut libc:
15261526
info!(context, 0, "Testing {} ...", to_string(url));
15271527

15281528
match reqwest::Client::new()
1529-
.get(to_str(url))
1529+
.get(as_str(url))
15301530
.send()
15311531
.and_then(|mut res| res.text())
15321532
{

src/dc_contact.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ pub unsafe fn dc_get_contact_encrinfo(
779779
let peerstate = Peerstate::from_addr(
780780
context,
781781
&context.sql.clone().read().unwrap(),
782-
to_str((*contact).addr),
782+
as_str((*contact).addr),
783783
);
784784
dc_loginparam_read(
785785
context,
@@ -831,7 +831,7 @@ pub unsafe fn dc_get_contact_encrinfo(
831831
.map(|k| k.formatted_fingerprint_c())
832832
.unwrap_or(std::ptr::null_mut());
833833
if peerstate.addr.is_some()
834-
&& to_str((*loginparam).addr) < peerstate.addr.as_ref().unwrap().as_str()
834+
&& as_str((*loginparam).addr) < peerstate.addr.as_ref().unwrap().as_str()
835835
{
836836
cat_fingerprint(
837837
&mut ret,
@@ -1121,7 +1121,7 @@ pub unsafe fn dc_contact_is_verified_ex<'a>(
11211121
let peerstate = Peerstate::from_addr(
11221122
(*contact).context,
11231123
&(*contact).context.sql.clone().read().unwrap(),
1124-
to_str((*contact).addr),
1124+
as_str((*contact).addr),
11251125
);
11261126

11271127
let res = if let Some(ps) = peerstate {

src/dc_e2ee.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pub unsafe fn dc_e2ee_encrypt(
121121
let peerstate = Peerstate::from_addr(
122122
context,
123123
&context.sql.clone().read().unwrap(),
124-
to_str(recipient_addr),
124+
as_str(recipient_addr),
125125
);
126126
if peerstate.is_some()
127127
&& (peerstate.as_ref().unwrap().prefer_encrypt
@@ -613,7 +613,7 @@ pub unsafe fn dc_e2ee_decrypt(
613613
let autocryptheader = Aheader::from_imffields(from, imffields);
614614
if message_time > 0 && !from.is_null() {
615615
peerstate =
616-
Peerstate::from_addr(context, &context.sql.clone().read().unwrap(), to_str(from));
616+
Peerstate::from_addr(context, &context.sql.clone().read().unwrap(), as_str(from));
617617

618618
if let Some(ref mut peerstate) = peerstate {
619619
if let Some(ref header) = autocryptheader {
@@ -648,7 +648,7 @@ pub unsafe fn dc_e2ee_decrypt(
648648
peerstate = Peerstate::from_addr(
649649
&context,
650650
&context.sql.clone().read().unwrap(),
651-
to_str(from),
651+
as_str(from),
652652
);
653653
}
654654
if let Some(ref peerstate) = peerstate {

src/dc_imex.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub unsafe fn dc_imex_has_backup(
5252
let mut curr_pathNfilename: *mut libc::c_char = 0 as *mut libc::c_char;
5353
let mut test_sql: Option<dc_sqlite3_t> = None;
5454

55-
let dir = std::path::Path::new(to_str(dir_name));
55+
let dir = std::path::Path::new(as_str(dir_name));
5656

5757
if dir.is_dir() {
5858
match std::fs::read_dir(dir) {
@@ -1174,7 +1174,7 @@ unsafe fn export_backup(context: &Context, dir: *const libc::c_char) -> libc::c_
11741174
11487273724841241105 => {}
11751175
_ => {
11761176
let mut total_files_cnt = 0;
1177-
let dir = std::path::Path::new(to_str(context.get_blobdir()));
1177+
let dir = std::path::Path::new(as_str(context.get_blobdir()));
11781178
let dir_handle = std::fs::read_dir(dir);
11791179
if dir_handle.is_err() {
11801180
dc_log_error(
@@ -1378,7 +1378,7 @@ unsafe fn import_self_keys(context: &Context, dir_name: *const libc::c_char) ->
13781378
// a pointer inside buf2, MUST NOT be free()'d
13791379
let mut buf2_headerline: *const libc::c_char = 0 as *const libc::c_char;
13801380
if !dir_name.is_null() {
1381-
let dir = std::path::Path::new(to_str(dir_name));
1381+
let dir = std::path::Path::new(as_str(dir_name));
13821382
let dir_handle = std::fs::read_dir(dir);
13831383
if dir_handle.is_err() {
13841384
dc_log_error(

src/dc_job.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,13 +486,13 @@ unsafe fn dc_job_do_DC_JOB_MOVE_MSG(context: &Context, job: &mut dc_job_t) {
486486
);
487487

488488
if !dest_folder.is_null() {
489-
let server_folder = to_str((*msg).server_folder);
489+
let server_folder = as_str((*msg).server_folder);
490490

491491
match inbox.mv(
492492
context,
493493
server_folder,
494494
(*msg).server_uid,
495-
to_str(dest_folder),
495+
as_str(dest_folder),
496496
&mut dest_uid,
497497
) as libc::c_uint
498498
{
@@ -593,7 +593,7 @@ unsafe fn dc_job_do_DC_JOB_MARKSEEN_MDN_ON_IMAP(context: &Context, job: &mut dc_
593593
0 as *const libc::c_char,
594594
);
595595
if !dest_folder.is_null() {
596-
let dest_folder = to_str(dest_folder);
596+
let dest_folder = as_str(dest_folder);
597597
if 1 == inbox.mv(context, folder, uid, dest_folder, &mut dest_uid)
598598
as libc::c_uint
599599
{

0 commit comments

Comments
 (0)