Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

文字列を逆順にする

それでは次に、クライアントが送信したテキストを逆順にして応答するようにして、サーバーをもう少し面白くしてみましょう。サーバーは、 クライアントが ENTER キーを押すたびに応答を返します。各サーバー応答は新しい行に 出力されます。

今回はバッファが必要です。heapless::Vec を使えます。スターターコードは次のとおりです。

#![deny(unsafe_code)]
#![no_main]
#![no_std]

#[allow(unused_imports)]
use aux11::{entry, iprint, iprintln};
use heapless::Vec;

#[entry]
fn main() -> ! {
    let (usart1, _mono_timer, _itm) = aux11::init();

    // A buffer with 32 bytes of capacity
    let mut buffer: Vec<u8, 32> = Vec::new();

    loop {
        buffer.clear();

        // TODO Receive a user request. Each user request ends with ENTER
        // NOTE `buffer.push` returns a `Result`. Handle the error by responding
        // with an error message.

        // TODO Send back the reversed string
    }
}