Skip to content

Others

Selecting Your Language

For the "Other" section, let's consider a Rust program. Ensure the project is developed in Rust.

Here is an example Rust Sample

Structuring Your Project

A typical structure for a Rust project ready for packaging might look like this:

my_rust_project/
├── src/
│   └── main.rs  # Your main application file.
├── Cargo.toml  # Describes your project and its dependencies.
├── Cargo.lock  # Ensures consistent builds.
  1. Main File: The main Rust file, main.rs, should reside in the src directory, serving as the application's entry point.
  2. Dependencies: The Cargo.toml file at the root lists all project dependencies. Defining Cargo.toml and executing cargo build generates a target directory and Cargo.lock, assuring build consistency.
  3. Compilation: Use cargo build --release to compile the project, creating an executable in target/release. For upload, include only the executable, excluding the entire target directory.

Defining the Entry Point

The entry point for Rust projects is the main function in src/main.rs.

Example Code

Your Rust application might look like this:

use std::io::prelude::*;
use std::net::TcpListener;
use std::net::TcpStream;

fn main() {
    let listener = TcpListener::bind("0.0.0.0:8080").unwrap();
    println!("Running on 0.0.0.0:8080");
    for stream in listener.incoming() {
        let stream = stream.unwrap();
        handle_connection(stream);
    }
}

fn handle_connection(mut stream: TcpStream) {
    println!("handling connection");

    const MSG: &str = "helloworld";
    let response = format!("{:x?}", MSG.as_bytes());

    let mut buffer = [0; 1024];
    stream.read(&mut buffer).unwrap();

    let response = format!("HTTP/1.1 200 OK\nContent-Type: text/plain\n\nOKIDOK\n{}", response);
    stream.write(response.as_bytes()).unwrap();
    stream.flush().unwrap();
}

Uploading Your Code

To deploy your Rust application on the platform:

  1. Navigate to Code Upload: Access the code upload section by creating a new function.
  2. Choose File: Select your packaged file containing the compiled binary.
  3. Select Language: Choose Rust as the language.
  4. Specify Entry Point: The entry point is defined in your Cargo.toml and implemented in src/main.rs.
  5. Upload: Submit your package for processing.