You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: spi.rs
    path of file: ./repos/tock/chips/stm32f303xc/src
    
    the code of the file until where you have to start completion: // Licensed under the Apache License, Version 2.0 or the MIT License.
// SPDX-License-Identifier: Apache-2.0 OR MIT
// Copyright Tock Contributors 2022.

use core::cell::Cell;
use core::cmp;
use kernel::ErrorCode;


    
    fn set_rate(&self, rate: u32) -> Result<u32, ErrorCode> {
        // debug! ("stm32f3 spi set rate");
        if rate != 1_000_000 {
            return Err(ErrorCode::INVAL);
        }

        self.set_cr(|| {
            // HSI is 8Mhz and Fpclk is also 8Mhz. 0b010 is Fpclk / 8
            self.registers.cr1.modify(CR1::BR.val(0b010));
        });

        Ok(1_000_000)
    }