フィート&ヤードからメートルへのコンバーター
Rust と WebAssembly を使用して、単純なフィートとヤードからメートルへのコンバーター Web アプリを構築しましょう。このガイドでは、合理的なアプローチを提供します。
まず、Rust がシステムにインストールされていることを確認します。 https://www.php.cn/link/29f81692d9af87c8826aafca8ff5dad3からダウンロードしてインストールします。
次に、Cargo を使用して新しい Rust プロジェクトを作成します。
cargo new yardandfeetconverter
Cargo.toml
ファイルを変更して wasm-bindgen
依存関係を組み込み、クレート タイプを指定します。
[dependencies] wasm-bindgen = "0.2" [lib] crate-type = ["cdylib"]
src
ディレクトリに移動し、main.rs
の名前を lib.rs
に変更します。 lib.rs
の内容を次の変換ロジックに置き換えます:
use wasm_bindgen::prelude::*; #[wasm_bindgen] pub fn yards_to_meters(yards: f64) -> f64 { yards * 0.9144 } #[wasm_bindgen] pub fn feet_to_meters(feet: f64) -> f64 { feet * 0.3048 }
WebAssembly モジュールをビルドします:
wasm-pack build --target web
これにより、必要な Web ファイルが生成されます。 ここで、index.html
ディレクトリに yardandfeetconverter
ファイルを作成します。 次のコードを index.html
に貼り付けます:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Yard and Feet to Meters Converter</title> <style> body { font-family: Arial, sans-serif; margin: 0; padding: 0; display: flex; justify-content: center; align-items: center; min-height: 100vh; background: linear-gradient(to right, #4facfe, #00f2fe); } .container { text-align: center; background: white; padding: 2rem; border-radius: 10px; box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1); } input, select, button { margin: 10px; padding: 10px; font-size: 16px; border: 1px solid #ccc; border-radius: 5px; } button { background-color: #4facfe; color: white; cursor: pointer; } button:hover { background-color: #00c4cc; } </style> </head> <body> <div class="container"> <h1>Feet & Yards to Meters Converter</h1> <input type="number" id="value" placeholder="Enter value"> <select id="unit"> <option value="yards">Yards</option> <option value="feet">Feet</option> </select> <button id="convert">Convert</button> <p id="result"></p> </div> <script type="module"> import init, { yards_to_meters, feet_to_meters } from "./pkg/yardandfeetconverter.js"; async function setup() { await init(); document.getElementById('convert').addEventListener('click', () => { const value = parseFloat(document.getElementById('value').value); const type = document.getElementById('unit').value; let result; if (type === 'yards') { result = yards_to_meters(value); } else { result = feet_to_meters(value); } document.getElementById('result').innerText = `Result: ${result.toFixed(4)} meters`; }); } setup(); </script> </body> </html>
ローカル Web サーバーを起動します (例: Python の http.server
を使用):
python -m http.server
ブラウザを開いて localhost:8000
に移動します。 フィートとヤードをメートルに変換できるようになりました!
以上がフィート&ヤードからメートルへのコンバーターの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

メモ帳++7.3.1
使いやすく無料のコードエディター

SublimeText3 中国語版
中国語版、とても使いやすい

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

ホットトピック











新しいプロジェクトの開始時に、SASSコンピレーションは瞬く間に起こります。これは、特にbrowsersyncとペアになっている場合は素晴らしい気分です。

今週のプラットフォームニュースのラウンドアップで、Chromeは、Web開発者のロード、アクセシビリティ仕様、およびBBCの動きのための新しい属性を導入します

これは私が初めてHTML要素を見ていることです。私はしばらくの間それを知っていましたが、まだスピンしていませんでした。かなりクールです

購入またはビルドは、テクノロジーの古典的な議論です。自分で物を構築することは、あなたのクレジットカードの請求書にはラインアイテムがないため、安価に感じるかもしれませんが

しばらくの間、iTunesはポッドキャストの大きな犬だったので、「ポッドキャストにサブスクライブ」をリンクした場合:

今週のラウンドアップ、タイポグラフィを検査するための便利なブックマークレットである。

サイトの訪問者と使用データを追跡するのに役立つ分析プラットフォームがたくさんあります。おそらく、特にGoogleアナリティクスが広く使用されています
