У нас вы можете посмотреть бесплатно Rust Tip - Into String as Function Arguments или скачать в максимальном доступном качестве, видео которое было загружено на ютуб. Для загрузки выберите вариант из формы ниже:
Если кнопки скачивания не
загрузились
НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если возникают проблемы со скачиванием видео, пожалуйста напишите в поддержку по адресу внизу
страницы.
Спасибо за использование сервиса ClipSaver.ru
Here is a quick Rust Programming tutorial showing how to type function arguments to accept &str, &String, and String (which will be moved). This is useful when the body of the function needs the full String no matter what is passed. Help support this channel: / jeremychone When &str or &String is passed as an argument, new string allocation occurs on .into() When String is passed, no new allocation occurs on .into(). The String is moved to the function. So, in a way, this technique gives allocation control to the caller. Notes for this pattern: 1. Do not use this pattern if the function body does not need to own the String, and can get away &String or &str. Use &str in this case. 2. Some might think this pattern makes necessary allocation, but this is not the case (see video and points above). It is allocated only in the case of &str or &String are passed (which would have been anyway), and not if String is passed. The caaller has the control. 3 Downsides: 3.1 Binary size: As noted in a great comment from @JeffHanke below, the compiler will duplicate the function for each unique type passed (monomorphization). See (and vote) the comment for the binary size mitigation. For most app code, the cost should be negligible, moreover, if mitigated, compared to the ergonomic value (watch out for compiler inlining, but this can be mitigated as well). For embedded programming, this needs a little bit more scrutiny, as many other aspects of the code design anyway. 3.2 Function ergonomics could be a discussion, but it is subjective. I personally like this pattern as the method signature is clear, flexible, and efficient, as allocation will only occur if needed. But do what works for you and your team. 3.3 Unnecessary discussions about unnecessary allocations (see point 2 above). Related external resources: https://www.philipdaniels.com/blog/20... (Scroll down to Into section) https://rust-lang.github.io/api-guide... (more generic but related "caller-decides" topic, see generic paragraphs) Related external resources: https://www.philipdaniels.com/blog/20... (Scroll down to Into section) https://rust-lang.github.io/api-guide... (more generic but related "caller-decides" topic, see generic paragraphs) Jeremy Chone: Twitter - / jeremychone Discord On Rust - / discord AWESOME-APP - https://awesomeapp.dev - Rust Templates for building awesome applications. Patreon - / jeremychone - Any help is a big help (for Rust educational content) Other popular Rust Programming videos: Quick Start Code Layout - • Rust - Simple Code Boilerplate & Structure... AWESOME-APP Full Overview - Rust template for building Awesome Desktop Application: • Building Awesome Desktop App with Rust, Ta... Tauri Quick Introduction (Desktop App wit Rust Programming): • Rust Tauri 1.0 - Quick Intro - Rust Deskto... Rust Web App tutorials series: • Rust Web App - 1/3 - Data Access Rust Bevy Full Tutorial - Game Development with Rust: • Rust Bevy Full Tutorial - Game Development... Rust for Java Developers series: • Rust for Java Developers 1/3 - Introductio... Playlists: Rust For Desktop App: • JC - Rust Programming for Desktop App Everything Rust Programming - Tutorials, Courses, Tips, Examples: • JC - Rust - Everything Rust Programming - ... Rust Programming for Web Development: • JC - Rust Programming for Web Development Rust Courses: • Rust Course 2021 by the book | RustLang Furst for Java Developers: • Rust for Java Developers AWESOME-APP ➜ https://awesomeapp.dev - Rust Templates for building awesome applications. Rust AWESOME-APP GitHub - https://github.com/orgs/rust-awesome-... Other notes: Tool used to do the green lines. ScreenBrush on Mac App Store (Gromit seems to be the equivalent on Linux) Edited with Davinci Resolve. #rustprogramming #tutorial #rustlangn